<!DOCTYPE html><html lang="zh-Hans"><head><meta charset="utf-8"><title>Angular - 响应式表单</title><meta name="Description" content="Angular is a platform for building mobile and desktop web applications.
    Join the community of millions of developers who build compelling user interfaces with Angular."><base href="/"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="search" type="application/opensearchdescription+xml" href="assets/opensearch.xml"><link rel="icon" type="image/x-icon" href="assets/images/favicons/favicon.ico"><link rel="icon" type="image/png" href="assets/images/favicons/favicon-32x32.png" sizes="32x32"><link rel="icon" type="image/png" href="assets/images/favicons/favicon-194x194.png" sizes="194x194"><link rel="icon" type="image/png" href="assets/images/favicons/favicon-96x96.png" sizes="96x96"><link rel="icon" type="image/png" href="assets/images/favicons/favicon-16x16.png" sizes="16x16"><link rel="apple-touch-icon" sizes="144x144" href="assets/images/favicons/favicon-144x144.png"><link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/images/favicons/favicon-144x144.png"><link href="assets/fonts/Material_Icons.css" rel="stylesheet"><link href="assets/fonts/Droid_Sans_Mono.css" rel="stylesheet"><link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"><link rel="manifest" href="pwa-manifest.json"><meta name="theme-color" content="#1976d2"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="translucent"><script async="" src="assets/js/analytics.js"></script><script>!function(e,a,n,t,s,c,g){e.GoogleAnalyticsObject=s,e.ga=e.ga||function(){(e.ga.q=e.ga.q||[]).push(arguments)},e.ga.l=1*new Date,c=a.createElement(n),g=a.getElementsByTagName(n)[0],c.async=1,c.src="assets/js/analytics.js",~e.name.indexOf("NG_DEFER_BOOTSTRAP")||g.parentNode.insertBefore(c,g)}(window,document,"script",0,"ga")</script><script>window.onerror=function(){ga("send","exception",{exDescription:function(e,r,n,a,c){var l;e=e.replace(/^Error: /,""),l=c?c.stack.replace(/^Error: /,"").replace(e+"\n","").replace(/^ +/gm,"").replace(/^at /gm,"").replace(/(?: \(|@)http.+\/([^/)]+)\)?(?:\n|$)/gm,"@$1\n").replace(/ *\(eval code(:\d+:\d+)\)(?:\n|$)/gm,"@???$1\n"):r+":"+(n=n||"?")+":"+(a=a||"?");return(e+"\n"+l).substr(0,150)}.apply(null,arguments),exFatal:!0})}</script><link rel="stylesheet" href="styles.4adbe52ad34df01b5273.css"><style>.cdk-high-contrast-active .mat-toolbar{outline:solid 1px}.mat-toolbar-row,.mat-toolbar-single-row{display:flex;box-sizing:border-box;padding:0 16px;width:100%;flex-direction:row;align-items:center;white-space:nowrap}.mat-toolbar-multiple-rows{display:flex;box-sizing:border-box;flex-direction:column;width:100%}.mat-toolbar-multiple-rows{min-height:64px}.mat-toolbar-row,.mat-toolbar-single-row{height:64px}@media(max-width:599px){.mat-toolbar-multiple-rows{min-height:56px}.mat-toolbar-row,.mat-toolbar-single-row{height:56px}}</style><style>.mat-icon{background-repeat:no-repeat;display:inline-block;fill:currentColor;height:24px;width:24px}.mat-icon.mat-icon-inline{font-size:inherit;height:inherit;line-height:inherit;width:inherit}[dir=rtl] .mat-icon-rtl-mirror{transform:scale(-1,1)}.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-prefix .mat-icon,.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-suffix .mat-icon{display:block}.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-prefix .mat-icon-button .mat-icon,.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-suffix .mat-icon-button .mat-icon{margin:auto}</style><style>.mat-button .mat-button-focus-overlay,.mat-icon-button .mat-button-focus-overlay{opacity:0}.mat-button:hover .mat-button-focus-overlay,.mat-stroked-button:hover .mat-button-focus-overlay{opacity:.04}@media(hover:none){.mat-button:hover .mat-button-focus-overlay,.mat-stroked-button:hover .mat-button-focus-overlay{opacity:0}}.mat-button,.mat-flat-button,.mat-icon-button,.mat-stroked-button{box-sizing:border-box;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:pointer;outline:0;border:none;-webkit-tap-highlight-color:transparent;display:inline-block;white-space:nowrap;text-decoration:none;vertical-align:baseline;text-align:center;margin:0;min-width:64px;line-height:36px;padding:0 16px;border-radius:4px;overflow:visible}.mat-button::-moz-focus-inner,.mat-flat-button::-moz-focus-inner,.mat-icon-button::-moz-focus-inner,.mat-stroked-button::-moz-focus-inner{border:0}.mat-button[disabled],.mat-flat-button[disabled],.mat-icon-button[disabled],.mat-stroked-button[disabled]{cursor:default}.mat-button.cdk-keyboard-focused .mat-button-focus-overlay,.mat-button.cdk-program-focused .mat-button-focus-overlay,.mat-flat-button.cdk-keyboard-focused .mat-button-focus-overlay,.mat-flat-button.cdk-program-focused .mat-button-focus-overlay,.mat-icon-button.cdk-keyboard-focused .mat-button-focus-overlay,.mat-icon-button.cdk-program-focused .mat-button-focus-overlay,.mat-stroked-button.cdk-keyboard-focused .mat-button-focus-overlay,.mat-stroked-button.cdk-program-focused .mat-button-focus-overlay{opacity:.12}.mat-button::-moz-focus-inner,.mat-flat-button::-moz-focus-inner,.mat-icon-button::-moz-focus-inner,.mat-stroked-button::-moz-focus-inner{border:0}.mat-raised-button{box-sizing:border-box;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:pointer;outline:0;border:none;-webkit-tap-highlight-color:transparent;display:inline-block;white-space:nowrap;text-decoration:none;vertical-align:baseline;text-align:center;margin:0;min-width:64px;line-height:36px;padding:0 16px;border-radius:4px;overflow:visible;transform:translate3d(0,0,0);transition:background .4s cubic-bezier(.25,.8,.25,1),box-shadow 280ms cubic-bezier(.4,0,.2,1)}.mat-raised-button::-moz-focus-inner{border:0}.mat-raised-button[disabled]{cursor:default}.mat-raised-button.cdk-keyboard-focused .mat-button-focus-overlay,.mat-raised-button.cdk-program-focused .mat-button-focus-overlay{opacity:.12}.mat-raised-button::-moz-focus-inner{border:0}._mat-animation-noopable.mat-raised-button{transition:none;animation:none}.mat-stroked-button{border:1px solid currentColor;padding:0 15px;line-height:34px}.mat-stroked-button .mat-button-focus-overlay,.mat-stroked-button .mat-button-ripple.mat-ripple{top:-1px;left:-1px;right:-1px;bottom:-1px}.mat-fab{box-sizing:border-box;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:pointer;outline:0;border:none;-webkit-tap-highlight-color:transparent;display:inline-block;white-space:nowrap;text-decoration:none;vertical-align:baseline;text-align:center;margin:0;min-width:64px;line-height:36px;padding:0 16px;border-radius:4px;overflow:visible;transform:translate3d(0,0,0);transition:background .4s cubic-bezier(.25,.8,.25,1),box-shadow 280ms cubic-bezier(.4,0,.2,1);min-width:0;border-radius:50%;width:56px;height:56px;padding:0;flex-shrink:0}.mat-fab::-moz-focus-inner{border:0}.mat-fab[disabled]{cursor:default}.mat-fab.cdk-keyboard-focused .mat-button-focus-overlay,.mat-fab.cdk-program-focused .mat-button-focus-overlay{opacity:.12}.mat-fab::-moz-focus-inner{border:0}._mat-animation-noopable.mat-fab{transition:none;animation:none}.mat-fab .mat-button-wrapper{padding:16px 0;display:inline-block;line-height:24px}.mat-mini-fab{box-sizing:border-box;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:pointer;outline:0;border:none;-webkit-tap-highlight-color:transparent;display:inline-block;white-space:nowrap;text-decoration:none;vertical-align:baseline;text-align:center;margin:0;min-width:64px;line-height:36px;padding:0 16px;border-radius:4px;overflow:visible;transform:translate3d(0,0,0);transition:background .4s cubic-bezier(.25,.8,.25,1),box-shadow 280ms cubic-bezier(.4,0,.2,1);min-width:0;border-radius:50%;width:40px;height:40px;padding:0;flex-shrink:0}.mat-mini-fab::-moz-focus-inner{border:0}.mat-mini-fab[disabled]{cursor:default}.mat-mini-fab.cdk-keyboard-focused .mat-button-focus-overlay,.mat-mini-fab.cdk-program-focused .mat-button-focus-overlay{opacity:.12}.mat-mini-fab::-moz-focus-inner{border:0}._mat-animation-noopable.mat-mini-fab{transition:none;animation:none}.mat-mini-fab .mat-button-wrapper{padding:8px 0;display:inline-block;line-height:24px}.mat-icon-button{padding:0;min-width:0;width:40px;height:40px;flex-shrink:0;line-height:40px;border-radius:50%}.mat-icon-button .mat-icon,.mat-icon-button i{line-height:24px}.mat-button-focus-overlay,.mat-button-ripple.mat-ripple{top:0;left:0;right:0;bottom:0;position:absolute;pointer-events:none;border-radius:inherit}.mat-button-ripple.mat-ripple:not(:empty){transform:translateZ(0)}.mat-button-focus-overlay{opacity:0;transition:opacity .2s cubic-bezier(.35,0,.25,1),background-color .2s cubic-bezier(.35,0,.25,1)}._mat-animation-noopable .mat-button-focus-overlay{transition:none}.cdk-high-contrast-active .mat-button-focus-overlay{background-color:#fff}.cdk-high-contrast-black-on-white .mat-button-focus-overlay{background-color:#000}.mat-button-ripple-round{border-radius:50%;z-index:1}.mat-button .mat-button-wrapper>*,.mat-fab .mat-button-wrapper>*,.mat-flat-button .mat-button-wrapper>*,.mat-icon-button .mat-button-wrapper>*,.mat-mini-fab .mat-button-wrapper>*,.mat-raised-button .mat-button-wrapper>*,.mat-stroked-button .mat-button-wrapper>*{vertical-align:middle}.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-prefix .mat-icon-button,.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-suffix .mat-icon-button{display:block;font-size:inherit;width:2.5em;height:2.5em}.cdk-high-contrast-active .mat-button,.cdk-high-contrast-active .mat-fab,.cdk-high-contrast-active .mat-flat-button,.cdk-high-contrast-active .mat-icon-button,.cdk-high-contrast-active .mat-mini-fab,.cdk-high-contrast-active .mat-raised-button{outline:solid 1px}</style><style>.mat-drawer-container{position:relative;z-index:1;box-sizing:border-box;-webkit-overflow-scrolling:touch;display:block;overflow:hidden}.mat-drawer-container[fullscreen]{top:0;left:0;right:0;bottom:0;position:absolute}.mat-drawer-container[fullscreen].mat-drawer-container-has-open{overflow:hidden}.mat-drawer-container.mat-drawer-container-explicit-backdrop .mat-drawer-side{z-index:3}.mat-drawer-container.ng-animate-disabled .mat-drawer-backdrop,.mat-drawer-container.ng-animate-disabled .mat-drawer-content,.ng-animate-disabled .mat-drawer-container .mat-drawer-backdrop,.ng-animate-disabled .mat-drawer-container .mat-drawer-content{transition:none}.mat-drawer-backdrop{top:0;left:0;right:0;bottom:0;position:absolute;display:block;z-index:3;visibility:hidden}.mat-drawer-backdrop.mat-drawer-shown{visibility:visible}.mat-drawer-transition .mat-drawer-backdrop{transition-duration:.4s;transition-timing-function:cubic-bezier(.25,.8,.25,1);transition-property:background-color,visibility}.cdk-high-contrast-active .mat-drawer-backdrop{opacity:.5}.mat-drawer-content{position:relative;z-index:1;display:block;height:100%;overflow:auto}.mat-drawer-transition .mat-drawer-content{transition-duration:.4s;transition-timing-function:cubic-bezier(.25,.8,.25,1);transition-property:transform,margin-left,margin-right}.mat-drawer{position:relative;z-index:4;display:block;position:absolute;top:0;bottom:0;z-index:3;outline:0;box-sizing:border-box;overflow-y:auto;transform:translate3d(-100%,0,0)}.cdk-high-contrast-active .mat-drawer,.cdk-high-contrast-active [dir=rtl] .mat-drawer.mat-drawer-end{border-right:solid 1px currentColor}.cdk-high-contrast-active .mat-drawer.mat-drawer-end,.cdk-high-contrast-active [dir=rtl] .mat-drawer{border-left:solid 1px currentColor;border-right:none}.mat-drawer.mat-drawer-side{z-index:2}.mat-drawer.mat-drawer-end{right:0;transform:translate3d(100%,0,0)}[dir=rtl] .mat-drawer{transform:translate3d(100%,0,0)}[dir=rtl] .mat-drawer.mat-drawer-end{left:0;right:auto;transform:translate3d(-100%,0,0)}.mat-drawer-inner-container{width:100%;height:100%;overflow:auto;-webkit-overflow-scrolling:touch}.mat-sidenav-fixed{position:fixed}</style><style>.nav-link.highlight[_ngcontent-ng-docs-c30]{color:#ff0}</style><style>.mat-progress-bar{display:block;height:4px;overflow:hidden;position:relative;transition:opacity 250ms linear;width:100%}._mat-animation-noopable.mat-progress-bar{transition:none;animation:none}.mat-progress-bar .mat-progress-bar-element,.mat-progress-bar .mat-progress-bar-fill::after{height:100%;position:absolute;width:100%}.mat-progress-bar .mat-progress-bar-background{width:calc(100% + 10px)}.cdk-high-contrast-active .mat-progress-bar .mat-progress-bar-background{display:none}.mat-progress-bar .mat-progress-bar-buffer{transform-origin:top left;transition:transform 250ms ease}.cdk-high-contrast-active .mat-progress-bar .mat-progress-bar-buffer{border-top:solid 5px;opacity:.5}.mat-progress-bar .mat-progress-bar-secondary{display:none}.mat-progress-bar .mat-progress-bar-fill{animation:none;transform-origin:top left;transition:transform 250ms ease}.cdk-high-contrast-active .mat-progress-bar .mat-progress-bar-fill{border-top:solid 4px}.mat-progress-bar .mat-progress-bar-fill::after{animation:none;content:"";display:inline-block;left:0}.mat-progress-bar[dir=rtl],[dir=rtl] .mat-progress-bar{transform:rotateY(180deg)}.mat-progress-bar[mode=query]{transform:rotateZ(180deg)}.mat-progress-bar[mode=query][dir=rtl],[dir=rtl] .mat-progress-bar[mode=query]{transform:rotateZ(180deg) rotateY(180deg)}.mat-progress-bar[mode=indeterminate] .mat-progress-bar-fill,.mat-progress-bar[mode=query] .mat-progress-bar-fill{transition:none}.mat-progress-bar[mode=indeterminate] .mat-progress-bar-primary,.mat-progress-bar[mode=query] .mat-progress-bar-primary{-webkit-backface-visibility:hidden;backface-visibility:hidden;animation:mat-progress-bar-primary-indeterminate-translate 2s infinite linear;left:-145.166611%}.mat-progress-bar[mode=indeterminate] .mat-progress-bar-primary.mat-progress-bar-fill::after,.mat-progress-bar[mode=query] .mat-progress-bar-primary.mat-progress-bar-fill::after{-webkit-backface-visibility:hidden;backface-visibility:hidden;animation:mat-progress-bar-primary-indeterminate-scale 2s infinite linear}.mat-progress-bar[mode=indeterminate] .mat-progress-bar-secondary,.mat-progress-bar[mode=query] .mat-progress-bar-secondary{-webkit-backface-visibility:hidden;backface-visibility:hidden;animation:mat-progress-bar-secondary-indeterminate-translate 2s infinite linear;left:-54.888891%;display:block}.mat-progress-bar[mode=indeterminate] .mat-progress-bar-secondary.mat-progress-bar-fill::after,.mat-progress-bar[mode=query] .mat-progress-bar-secondary.mat-progress-bar-fill::after{-webkit-backface-visibility:hidden;backface-visibility:hidden;animation:mat-progress-bar-secondary-indeterminate-scale 2s infinite linear}.mat-progress-bar[mode=buffer] .mat-progress-bar-background{-webkit-backface-visibility:hidden;backface-visibility:hidden;animation:mat-progress-bar-background-scroll 250ms infinite linear;display:block}.mat-progress-bar._mat-animation-noopable .mat-progress-bar-background,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-buffer,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-fill,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-fill::after,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-primary,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-primary.mat-progress-bar-fill::after,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-secondary,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-secondary.mat-progress-bar-fill::after{animation:none;transition:none}@keyframes mat-progress-bar-primary-indeterminate-translate{0%{transform:translateX(0)}20%{animation-timing-function:cubic-bezier(.5,0,.701732,.495819);transform:translateX(0)}59.15%{animation-timing-function:cubic-bezier(.302435,.381352,.55,.956352);transform:translateX(83.67142%)}100%{transform:translateX(200.611057%)}}@keyframes mat-progress-bar-primary-indeterminate-scale{0%{transform:scaleX(.08)}36.65%{animation-timing-function:cubic-bezier(.334731,.12482,.785844,1);transform:scaleX(.08)}69.15%{animation-timing-function:cubic-bezier(.06,.11,.6,1);transform:scaleX(.661479)}100%{transform:scaleX(.08)}}@keyframes mat-progress-bar-secondary-indeterminate-translate{0%{animation-timing-function:cubic-bezier(.15,0,.515058,.409685);transform:translateX(0)}25%{animation-timing-function:cubic-bezier(.31033,.284058,.8,.733712);transform:translateX(37.651913%)}48.35%{animation-timing-function:cubic-bezier(.4,.627035,.6,.902026);transform:translateX(84.386165%)}100%{transform:translateX(160.277782%)}}@keyframes mat-progress-bar-secondary-indeterminate-scale{0%{animation-timing-function:cubic-bezier(.15,0,.515058,.409685);transform:scaleX(.08)}19.15%{animation-timing-function:cubic-bezier(.31033,.284058,.8,.733712);transform:scaleX(.457104)}44.15%{animation-timing-function:cubic-bezier(.4,.627035,.6,.902026);transform:scaleX(.72796)}100%{transform:scaleX(.08)}}@keyframes mat-progress-bar-background-scroll{to{transform:translateX(-8px)}}</style><script charset="utf-8" src="toc-toc-module-es2015.f8531f591ee147aebcc6.js"></script><script charset="utf-8" src="default~code-code-example-module~code-code-tabs-module-es2015.9efcc76d2979a2e605e0.js"></script><script charset="utf-8" src="code-code-example-module-es2015.fa05e6f700453813d256.js"></script><script charset="utf-8" src="code-code-tabs-module-es2015.505e1e0a869946918011.js"></script><script charset="utf-8" src="live-example-live-example-module-es2015.a8023d1b084857ef476b.js"></script><script charset="utf-8" src="assets-js-prettify-js-es2015.ba856648f2dd2d930a9b.js"></script><style>.mat-card{transition:box-shadow 280ms cubic-bezier(.4,0,.2,1);display:block;position:relative;padding:16px;border-radius:4px}._mat-animation-noopable.mat-card{transition:none;animation:none}.mat-card .mat-divider-horizontal{position:absolute;left:0;width:100%}[dir=rtl] .mat-card .mat-divider-horizontal{left:auto;right:0}.mat-card .mat-divider-horizontal.mat-divider-inset{position:static;margin:0}[dir=rtl] .mat-card .mat-divider-horizontal.mat-divider-inset{margin-right:0}.cdk-high-contrast-active .mat-card{outline:solid 1px}.mat-card-actions,.mat-card-content,.mat-card-subtitle{display:block;margin-bottom:16px}.mat-card-title{display:block;margin-bottom:8px}.mat-card-actions{margin-left:-8px;margin-right:-8px;padding:8px 0}.mat-card-actions-align-end{display:flex;justify-content:flex-end}.mat-card-image{width:calc(100% + 32px);margin:0 -16px 16px -16px}.mat-card-footer{display:block;margin:0 -16px -16px -16px}.mat-card-actions .mat-button,.mat-card-actions .mat-raised-button,.mat-card-actions .mat-stroked-button{margin:0 8px}.mat-card-header{display:flex;flex-direction:row}.mat-card-header .mat-card-title{margin-bottom:12px}.mat-card-header-text{margin:0 16px}.mat-card-avatar{height:40px;width:40px;border-radius:50%;flex-shrink:0;object-fit:cover}.mat-card-title-group{display:flex;justify-content:space-between}.mat-card-sm-image{width:80px;height:80px}.mat-card-md-image{width:112px;height:112px}.mat-card-lg-image{width:152px;height:152px}.mat-card-xl-image{width:240px;height:240px;margin:-8px}.mat-card-title-group>.mat-card-xl-image{margin:-8px 0 8px}@media(max-width:599px){.mat-card-title-group{margin:0}.mat-card-xl-image{margin-left:0;margin-right:0}}.mat-card-content>:first-child,.mat-card>:first-child{margin-top:0}.mat-card-content>:last-child:not(.mat-card-footer),.mat-card>:last-child:not(.mat-card-footer){margin-bottom:0}.mat-card-image:first-child{margin-top:-16px;border-top-left-radius:inherit;border-top-right-radius:inherit}.mat-card>.mat-card-actions:last-child{margin-bottom:-8px;padding-bottom:0}.mat-card-actions .mat-button:first-child,.mat-card-actions .mat-raised-button:first-child,.mat-card-actions .mat-stroked-button:first-child{margin-left:0;margin-right:0}.mat-card-subtitle:not(:first-child),.mat-card-title:not(:first-child){margin-top:-4px}.mat-card-header .mat-card-subtitle:not(:first-child){margin-top:-8px}.mat-card>.mat-card-xl-image:first-child{margin-top:-8px}.mat-card>.mat-card-xl-image:last-child{margin-bottom:-8px}</style><style>.mat-tab-group{display:flex;flex-direction:column}.mat-tab-group.mat-tab-group-inverted-header{flex-direction:column-reverse}.mat-tab-label{height:48px;padding:0 24px;cursor:pointer;box-sizing:border-box;opacity:.6;min-width:160px;text-align:center;display:inline-flex;justify-content:center;align-items:center;white-space:nowrap;position:relative}.mat-tab-label:focus{outline:0}.mat-tab-label:focus:not(.mat-tab-disabled){opacity:1}.cdk-high-contrast-active .mat-tab-label:focus{outline:dotted 2px}.mat-tab-label.mat-tab-disabled{cursor:default}.cdk-high-contrast-active .mat-tab-label.mat-tab-disabled{opacity:.5}.mat-tab-label .mat-tab-label-content{display:inline-flex;justify-content:center;align-items:center;white-space:nowrap}.cdk-high-contrast-active .mat-tab-label{opacity:1}@media(max-width:599px){.mat-tab-label{padding:0 12px}}@media(max-width:959px){.mat-tab-label{padding:0 12px}}.mat-tab-group[mat-stretch-tabs]>.mat-tab-header .mat-tab-label{flex-basis:0;flex-grow:1}.mat-tab-body-wrapper{position:relative;overflow:hidden;display:flex;transition:height .5s cubic-bezier(.35,0,.25,1)}._mat-animation-noopable.mat-tab-body-wrapper{transition:none;animation:none}.mat-tab-body{top:0;left:0;right:0;bottom:0;position:absolute;display:block;overflow:hidden;flex-basis:100%}.mat-tab-body.mat-tab-body-active{position:relative;overflow-x:hidden;overflow-y:auto;z-index:1;flex-grow:1}.mat-tab-group.mat-tab-group-dynamic-height .mat-tab-body.mat-tab-body-active{overflow-y:hidden}</style><style>.mat-tab-header{display:flex;overflow:hidden;position:relative;flex-shrink:0}.mat-tab-header-pagination{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;position:relative;display:none;justify-content:center;align-items:center;min-width:32px;cursor:pointer;z-index:2;-webkit-tap-highlight-color:transparent;touch-action:none}.mat-tab-header-pagination-controls-enabled .mat-tab-header-pagination{display:flex}.mat-tab-header-pagination-before,.mat-tab-header-rtl .mat-tab-header-pagination-after{padding-left:4px}.mat-tab-header-pagination-before .mat-tab-header-pagination-chevron,.mat-tab-header-rtl .mat-tab-header-pagination-after .mat-tab-header-pagination-chevron{transform:rotate(-135deg)}.mat-tab-header-pagination-after,.mat-tab-header-rtl .mat-tab-header-pagination-before{padding-right:4px}.mat-tab-header-pagination-after .mat-tab-header-pagination-chevron,.mat-tab-header-rtl .mat-tab-header-pagination-before .mat-tab-header-pagination-chevron{transform:rotate(45deg)}.mat-tab-header-pagination-chevron{border-style:solid;border-width:2px 2px 0 0;content:"";height:8px;width:8px}.mat-tab-header-pagination-disabled{box-shadow:none;cursor:default}.mat-tab-list{flex-grow:1;position:relative;transition:transform .5s cubic-bezier(.35,0,.25,1)}.mat-ink-bar{position:absolute;bottom:0;height:2px;transition:.5s cubic-bezier(.35,0,.25,1)}._mat-animation-noopable.mat-ink-bar{transition:none;animation:none}.mat-tab-group-inverted-header .mat-ink-bar{bottom:auto;top:0}.cdk-high-contrast-active .mat-ink-bar{outline:solid 2px;height:0}.mat-tab-labels{display:flex}[mat-align-tabs=center] .mat-tab-labels{justify-content:center}[mat-align-tabs=end] .mat-tab-labels{justify-content:flex-end}.mat-tab-label-container{display:flex;flex-grow:1;overflow:hidden;z-index:1}._mat-animation-noopable.mat-tab-list{transition:none;animation:none}.mat-tab-label{height:48px;padding:0 24px;cursor:pointer;box-sizing:border-box;opacity:.6;min-width:160px;text-align:center;display:inline-flex;justify-content:center;align-items:center;white-space:nowrap;position:relative}.mat-tab-label:focus{outline:0}.mat-tab-label:focus:not(.mat-tab-disabled){opacity:1}.cdk-high-contrast-active .mat-tab-label:focus{outline:dotted 2px}.mat-tab-label.mat-tab-disabled{cursor:default}.cdk-high-contrast-active .mat-tab-label.mat-tab-disabled{opacity:.5}.mat-tab-label .mat-tab-label-content{display:inline-flex;justify-content:center;align-items:center;white-space:nowrap}.cdk-high-contrast-active .mat-tab-label{opacity:1}@media(max-width:599px){.mat-tab-label{min-width:72px}}</style><style>.mat-tab-body-content{height:100%;overflow:auto}.mat-tab-group-dynamic-height .mat-tab-body-content{overflow:hidden}</style></head><body><aio-shell ng-version="9.0.0-rc.11" class="aio-notification-hide folder-guide mode-stable page-guide-reactive-forms sidenav-open view-SideNav"><div id="top-of-page"></div><mat-toolbar color="primary" class="mat-toolbar app-toolbar no-print mat-primary mat-toolbar-multiple-rows"><mat-toolbar-row class="mat-toolbar-row notification-container"><aio-notification notificationid="survey-february-2019" expirationdate="2019-03-01" class="ng-tns-c22-0 ng-trigger ng-trigger-hideAnimation" style="height:0"><span class="content ng-tns-c22-0"><a href="http://bit.ly/angular-survey-2019" target="_blank" class="ng-tns-c22-0"><mat-icon role="img" svgicon="insert_comment" aria-label="Announcement" class="mat-icon notranslate icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M20 2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h14l4 4V4c0-1.1-.9-2-2-2zm-2 12H6v-2h12v2zm0-3H6V9h12v2zm0-3H6V6h12v2z"></path><path d="M0 0h24v24H0z" fill="none"></path></svg></mat-icon><span class="message"><b>填写这份《一分钟调查》</b>，帮我们（开发组）做得更好！</span><span class="action-button">去填写</span></a></span><button mat-icon-button="" aria-label="Close" class="close-button ng-tns-c22-0 mat-icon-button mat-button-base"><span class="mat-button-wrapper"><mat-icon role="img" svgicon="close" aria-label="Dismiss notification" class="mat-icon notranslate mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"></path><path d="M0 0h24v24H0z" fill="none"></path></svg></mat-icon></span><div matripple="" class="mat-ripple mat-button-ripple mat-button-ripple-round"></div><div class="mat-button-focus-overlay"></div></button></aio-notification></mat-toolbar-row><mat-toolbar-row class="mat-toolbar-row"><button mat-button="" title="Docs menu" class="hamburger mat-button mat-button-base"><span class="mat-button-wrapper"><mat-icon role="img" svgicon="menu" class="mat-icon notranslate mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"></path></svg></mat-icon></span><div matripple="" class="mat-ripple mat-button-ripple"></div><div class="mat-button-focus-overlay"></div></button><a href="/" class="nav-link home"><img src="assets/images/logos/angular/logo-nav@2x.png" width="150" height="40" title="Home" alt="Home" class="ng-star-inserted"></a><aio-top-menu _nghost-ng-docs-c30="" class="ng-star-inserted"><ul _ngcontent-ng-docs-c30="" role="navigation"><li _ngcontent-ng-docs-c30="" class="ng-star-inserted"><a _ngcontent-ng-docs-c30="" class="nav-link" href="features" title="特性"><span _ngcontent-ng-docs-c30="" class="nav-link-inner">特性</span></a></li><li _ngcontent-ng-docs-c30="" class="ng-star-inserted"><a _ngcontent-ng-docs-c30="" class="nav-link" href="docs" title="文档"><span _ngcontent-ng-docs-c30="" class="nav-link-inner">文档</span></a></li><li _ngcontent-ng-docs-c30="" class="ng-star-inserted"><a _ngcontent-ng-docs-c30="" class="nav-link" href="resources" title="资源"><span _ngcontent-ng-docs-c30="" class="nav-link-inner">资源</span></a></li><li _ngcontent-ng-docs-c30="" class="ng-star-inserted"><a _ngcontent-ng-docs-c30="" class="nav-link" href="events" title="会议"><span _ngcontent-ng-docs-c30="" class="nav-link-inner">会议</span></a></li><li _ngcontent-ng-docs-c30="" class="ng-star-inserted"><a _ngcontent-ng-docs-c30="" class="nav-link" href="https://blog.angular.io/" title="博客"><span _ngcontent-ng-docs-c30="" class="nav-link-inner">博客</span></a></li><li _ngcontent-ng-docs-c30="" class="ng-star-inserted"><a _ngcontent-ng-docs-c30="" class="nav-link" href="translations/cn/home" title="关于中文版"><span _ngcontent-ng-docs-c30="" class="nav-link-inner">关于中文版</span></a></li></ul></aio-top-menu><aio-search-box class="search-container"><input type="search" aria-label="search" placeholder="搜索"></aio-search-box><div class="toolbar-external-icons-container"><a href="https://twitter.com/angular" title="Twitter" aria-label="Angular on twitter"><mat-icon role="img" svgicon="logos:twitter" class="mat-icon notranslate mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 50 59" xmlns="http://www.w3.org/2000/svg"><path d="M50,9.3c-1.8,0.8-3.8,1.4-5.9,1.6c2.1-1.3,3.7-3.3,4.5-5.7c-2,1.2-4.2,2-6.5,2.5c-1.9-2-4.5-3.2-7.5-3.2c-5.7,0-10.3,4.6-10.3,10.3c0,0.8,0.1,1.6,0.3,2.3C16.1,16.7,8.5,12.6,3.5,6.4c-0.9,1.5-1.4,3.3-1.4,5.2c0,3.6,1.8,6.7,4.6,8.5C5,20,3.4,19.6,2,18.8c0,0,0,0.1,0,0.1c0,5,3.5,9.1,8.2,10.1c-0.9,0.2-1.8,0.4-2.7,0.4c-0.7,0-1.3-0.1-1.9-0.2c1.3,4.1,5.1,7,9.6,7.1c-3.5,2.8-7.9,4.4-12.7,4.4c-0.8,0-1.6,0-2.4-0.1c4.5,2.9,9.9,4.6,15.7,4.6c18.9,0,29.2-15.6,29.2-29.2c0-0.4,0-0.9,0-1.3C46.9,13.2,48.6,11.4,50,9.3z"></path></svg></mat-icon></a><a href="https://github.com/angular/angular" title="GitHub" aria-label="Angular on github"><mat-icon role="img" svgicon="logos:github" class="mat-icon notranslate mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 51.8 50.4" xmlns="http://www.w3.org/2000/svg"><path d="M25.9,0.2C11.8,0.2,0.3,11.7,0.3,25.8c0,11.3,7.3,20.9,17.5,24.3c1.3,0.2,1.7-0.6,1.7-1.2c0-0.6,0-2.6,0-4.8c-7.1,1.5-8.6-3-8.6-3c-1.2-3-2.8-3.7-2.8-3.7c-2.3-1.6,0.2-1.6,0.2-1.6c2.6,0.2,3.9,2.6,3.9,2.6c2.3,3.9,6,2.8,7.5,2.1c0.2-1.7,0.9-2.8,1.6-3.4c-5.7-0.6-11.7-2.8-11.7-12.7c0-2.8,1-5.1,2.6-6.9c-0.3-0.7-1.1-3.3,0.3-6.8c0,0,2.1-0.7,7,2.6c2-0.6,4.2-0.9,6.4-0.9c2.2,0,4.4,0.3,6.4,0.9c4.9-3.3,7-2.6,7-2.6c1.4,3.5,0.5,6.1,0.3,6.8c1.6,1.8,2.6,4.1,2.6,6.9c0,9.8-6,12-11.7,12.6c0.9,0.8,1.7,2.4,1.7,4.7c0,3.4,0,6.2,0,7c0,0.7,0.5,1.5,1.8,1.2c10.2-3.4,17.5-13,17.5-24.3C51.5,11.7,40.1,0.2,25.9,0.2z"></path></svg></mat-icon></a></div></mat-toolbar-row></mat-toolbar><mat-sidenav-container role="main" class="mat-drawer-container mat-sidenav-container sidenav-container mat-drawer-transition has-floating-toc"><div class="mat-drawer-backdrop ng-star-inserted"></div><div class="cdk-visually-hidden cdk-focus-trap-anchor" aria-hidden="true"></div><mat-sidenav tabindex="-1" class="mat-drawer mat-sidenav sidenav ng-tns-c18-1 ng-trigger ng-trigger-transform mat-drawer-side ng-star-inserted mat-drawer-opened" style="transform:none;visibility:visible"><div class="mat-drawer-inner-container ng-tns-c18-1"><aio-nav-menu class="ng-tns-c18-1"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-1 collapsed ng-star-inserted" style="position:relative" href="docs" title="Angular 文档简介" target="_self"><span>简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-1 collapsed ng-star-inserted" title="通过构建第一个 Angular 应用来学习基础知识" aria-pressed="false"><span>快速上手</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-1 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="start" title="介绍 Angular 的组件模型、模板语法和组件通讯" target="_self"><span>你的第一个应用</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="start/routing" title="介绍如何使用浏览器的 URL 在组件之间进行路由" target="_self"><span>路由</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="start/data" title="介绍服务以及如何访问外部数据" target="_self"><span>管理数据</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="start/forms" title="学习如何使用表单从用户那里获取并管理数据" target="_self"><span>表单</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="start/deployment" title="通过你的应用放到 Firebase 或自己的服务器上来把它分享给外界" target="_self"><span>部署</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-1 collapsed ng-star-inserted" style="position:relative" href="guide/setup-local" title="使用 Angular CLI 搭建本地开发环境简介" target="_self"><span>搭建环境</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-1 expanded selected ng-star-inserted" title="Angular 的基本原理" aria-pressed="true"><span>基本原理</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-1 expanded selected"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="介绍 Angular 应用中的一些基本概念。" aria-pressed="false"><span>Angular 的基本概念</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/architecture" title="Angular 应用中的基本构造块。" target="_self"><span>基本概念简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/architecture-modules" title="关于 Angular 模块（NgModules）。" target="_self"><span>模块简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/architecture-components" title="关于组件、模板和视图。" target="_self"><span>组件简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/architecture-services" title="关于服务与依赖注入。" target="_self"><span>服务与 DI 简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/architecture-next-steps" title="超越基础阶段。" target="_self"><span>后续步骤</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="英雄指南是这里大量 Angular 范例的基础" aria-pressed="false"><span>英雄指南</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="tutorial" title="《英雄指南》教程简介" target="_self"><span>简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="tutorial/toh-pt0" title="创建应用的外壳" target="_self"><span>应用的“外壳”</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="tutorial/toh-pt1" title="第一部分：构建一个简单的英雄编辑器" target="_self"><span>1. 英雄编辑器</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="tutorial/toh-pt2" title="第二部分：构建一个主从结构的页面，用于展现英雄列表。" target="_self"><span>2. 显示英雄列表</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="tutorial/toh-pt3" title="第三部分：把主从结构的视图重构成几个独立的组件。" target="_self"><span>3. 创建特性组件</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="tutorial/toh-pt4" title="第四部分：创建一个可复用的服务来管理英雄数据。" target="_self"><span>4. 添加服务</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="tutorial/toh-pt5" title="第五部分：添加 Angular 路由器，并且学习在视图之间导航。" target="_self"><span>5. 添加应用内导航</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="tutorial/toh-pt6" title="第六部分：通过 HTTP 来获取并保存英雄数据。" target="_self"><span>6. 从服务器获取数据</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="通过数据绑定构建动态视图" aria-pressed="false"><span>组件与模板</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/displaying-data" title="属性绑定可以帮助应用把数据显示在界面上" target="_self"><span>显示数据</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/template-syntax" title="学习如何写模板，以便借助数据绑定机制显示数据并响应事件。" target="_self"><span>模板语法</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/user-input" title="用户输入会触发 DOM 事件。Angular 会通过事件绑定来监听那些事件，并把修改后的值传回应用的组件和模型中。" target="_self"><span>用户输入</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/lifecycle-hooks" title="Angular 调用指令和组件的生命周期钩子函数，包括它的创建、变更和销毁时。" target="_self"><span>生命周期钩子</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/component-interaction" title="在不同的指令和组件之间共享信息" target="_self"><span>组件交互</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/component-styles" title="添加专属于某个组件的样式" target="_self"><span>组件样式</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/dynamic-component-loader" title="动态加载组件" target="_self"><span>动态组件</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/elements" title="把组件转换成自定义元素" target="_self"><span>Angular 元素</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/attribute-directives" title="属性型指令把行为添加到现有元素上。" target="_self"><span>属性型指令</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/structural-directives" title="结构型指令可以操纵页面的布局" target="_self"><span>结构型指令</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/pipes" title="管道可以在模板中转换显示的内容。" target="_self"><span>管道</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 expanded selected ng-star-inserted" title="Angular 的表单" aria-pressed="true"><span>表单</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 expanded selected"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/forms-overview" title="表单可以创建集中、高效、引人注目的输入体验。Angular 表单可以协调一组数据绑定控件，跟踪变更，验证输入，并表达错误信息。" target="_self"><span>简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 expanded selected ng-star-inserted" style="position:relative" href="guide/reactive-forms" title="使用 FormBuilder、表单组和表单数组创建响应式表单。" target="_self"><span>响应式表单</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/forms" title="使用指令和 Angular 模板语法创建模板驱动表单。" target="_self"><span>模板驱动表单</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/form-validation" title="验证用户的表单输入" target="_self"><span>表单验证</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/dynamic-form" title="使用 FormGroup 渲染动态表单。" target="_self"><span>动态表单</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="Observable 与 RxJS" aria-pressed="false"><span>Observable 与 RxJS</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/observables" title="" target="_self"><span>可观察对象(Observable)</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/rx-library" title="" target="_self"><span>RxJS 库</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/observables-in-angular" title="" target="_self"><span>Angular 中的可观察对象</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/practical-observable-usage" title="" target="_self"><span>用法实战</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/comparing-observables" title="" target="_self"><span>与其它技术的比较</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="Angular 中的模块" aria-pressed="false"><span>NgModules</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/ngmodules" title="使用 NgModule 让你的应用更高效" target="_self"><span>NgModule 简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/ngmodule-vs-jsmodule" title="JavaScript 模块和 NgModule 之间的差异" target="_self"><span>JS 模块 vs NgModule</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/bootstrapping" title="告诉 Angular 如何在根 &quot;AppModule&quot; 中构造和引导应用。" target="_self"><span>应用的根模块</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/frequent-ngmodules" title="介绍最常用的 NgModule" target="_self"><span>常用模块</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/module-types" title="介绍特性模块的几种类型" target="_self"><span>特性模块的分类</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/entry-components" title="关于 Angular 中入口组件的一切" target="_self"><span>入口组件</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/feature-modules" title="创建特性模块，以组织你的代码" target="_self"><span>特性模块</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/providers" title="服务提供商与 NgModule" target="_self"><span>服务提供商</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/singleton-services" title="创建单例服务" target="_self"><span>单例服务</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/lazy-loading-ngmodules" title="惰性加载模块，以提高应用的性能" target="_self"><span>惰性加载的特性模块</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/sharing-ngmodules" title="共享 NgModule 让你的应用现代化。" target="_self"><span>共享 NgModule</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/ngmodule-api" title="理解 NgModule 的那些细节。" target="_self"><span>NgModule API</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/ngmodule-faq" title="回答关于 NgModules 的常见问题。" target="_self"><span>NgModule 常见问题</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="依赖注入：创建并注入各种服务。" aria-pressed="false"><span>依赖注入</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/dependency-injection" title="Angular 的依赖注入系统能够为 Angular 创建的类创建并交付它们所依赖的服务。" target="_self"><span>Angular 依赖注入</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/hierarchical-dependency-injection" title="与组件树平行的注入器树，并支持嵌套的依赖。" target="_self"><span>多级注入器</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/dependency-injection-providers" title="各种提供商类型的更多知识。" target="_self"><span>DI 提供商</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/dependency-injection-in-action" title="依赖注入的使用技巧" target="_self"><span>DI 实战</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/dependency-injection-navtree" title="使用注入器树来查找父组件。" target="_self"><span>浏览组件树</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/http" title="通过 HTTP 协议与远程服务器对话。" target="_self"><span>HttpClient</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/router" title="揭示如何通过 Angular 路由进行基本的屏幕导航。" target="_self"><span>路由与导航</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="Angular 动画系统指南" aria-pressed="false"><span>动画</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/animations" title="Angular 动画的基础技术。" target="_self"><span>简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/transition-and-triggers" title="转场与触发器的高级技术。" target="_self"><span>转场与触发器</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/complex-animation-sequences" title="复杂的 Angular 动画序列。" target="_self"><span>复杂序列</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/reusable-animations" title="创建可复用的动画。" target="_self"><span>可复用动画</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/route-animations" title="为路由提供转场动画。" target="_self"><span>路由转场动画</span></a></div></aio-nav-item></div></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-1 collapsed ng-star-inserted" title="把 Angular 用到你的实际工作中的一些技巧" aria-pressed="false"><span>其它技术</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-1 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/security" title="Angular 应用开发中的安全技术。" target="_self"><span>安全</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/i18n" title="把应用模板中的文本翻译成多种语言。" target="_self"><span>国际化（i18n）</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/accessibility" title="设计能被所有用户访问的应用" target="_self"><span>无障碍（a11y）</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="Angular Service Worker: 控制应用资源的缓存。" aria-pressed="false"><span>Service Worker 与 PWA</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/service-worker-intro" title="Angular 对 Service Worker 的实现提升了慢速或不稳定的网络连接下的用户体验。" target="_self"><span>简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/service-worker-getting-started" title="在 CLI 项目中启用 Service Worker，并在浏览器中查看效果。" target="_self"><span>快速上手</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/app-shell" title="在 CLI 项目中启用应用外壳。" target="_self"><span>应用外壳</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/service-worker-communications" title="那些能让你和 Angular 的 Service Worker 通讯的服务类。" target="_self"><span>与 Service Worker 通讯</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/service-worker-devops" title="使用 Service Worker 运行应用、管理应用更新、调试以及杀掉正在运行的应用。" target="_self"><span>生产环境下的 Service Worker</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/service-worker-config" title="配置 Service Worker 的缓存行为。" target="_self"><span>Service Worker 配置</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/universal" title="使用 Angular Universal 在服务端渲染 HTML。" target="_self"><span>服务端渲染</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="把 AngularJS 应用增量式的升级到 Angular。" aria-pressed="false"><span>从 AngularJS 升级</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/upgrade" title="把 AngularJS 应用增量式的升级到 Angular。" target="_self"><span>升级步骤</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/upgrade-performance" title="用更灵活的方式把 AngularJS 升级到 Angular。" target="_self"><span>更关注性能的升级方式</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/ajs-quick-reference" title="学习如何把 AngularJS 的概念映射到 Angular 中。" target="_self"><span>AngularJS 与 Angular 的概念对照</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="使用共享库扩展 Angular" aria-pressed="false"><span>开发 Angular 库</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/libraries" title="理解何时以及如何使用和创建库。" target="_self"><span>库概览</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/using-libraries" title="把已发布的库集成进你的应用中。" target="_self"><span>使用已发布的库</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/creating-libraries" title="通过创建、发布和使用你自己的库来扩展 Angular。" target="_self"><span>创建库</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="理解原理图" aria-pressed="false"><span>原理图（Schematic）</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/schematics" title="理解 Angular 如何使用原理图。" target="_self"><span>原理图概览</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/schematics-authoring" title="理解原理图的结构。" target="_self"><span>制作原理图</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/schematics-for-libraries" title="使用原理图来把你的库集成进 Angular CLI 中。" target="_self"><span>库的原理图</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/cli-builder" title="使用构建器定制 Angular CLI。" target="_self"><span>CLI 构建器</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/web-worker" title="在 Angular CLI 中使用 Web Worker。" target="_self"><span>Web Worker</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-1 collapsed ng-star-inserted" title="关于构建、测试和部署的信息" aria-pressed="false"><span>开发工作流</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-1 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="理解 AOT 预先编译器。" aria-pressed="false"><span>AOT 预先编译器</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/aot-compiler" title="学习为何以及如何使用预先编译器。" target="_self"><span>预先编译</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/angular-compiler-options" title="配置 AOT 编译。" target="_self"><span>Angular 编译器选项</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/aot-metadata-errors" title="解决 AOT 编译错误。" target="_self"><span>AOT 元数据错误</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/template-typecheck" title="Angular 中的模板类型检查。" target="_self"><span>模板类型检查</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/build" title="构建应用及为应用启动开发服务器。" target="_self"><span>构建与运行</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/bazel" title="如何配置你的环境，以利用 Bazel 进行构建和测试。" target="_self"><span>使用 Bazel 进行构建</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/testing" title="测试 Angular 应用的技巧与实践。" target="_self"><span>测试</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/deployment" title="了解如何部署 Angular 应用。" target="_self"><span>发布</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="与开发环境和工具集成起来" aria-pressed="false"><span>开发工具集成</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/language-service" title="使用 Angular 语言服务加速开发。" target="_self"><span>语言服务</span></a></div></aio-nav-item></div></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-1 collapsed ng-star-inserted" title="工作空间与项目的结构，及其配置文件。" aria-pressed="false"><span>配置</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-1 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/file-structure" title="Angular 工作区在文件系统中是怎样的。" target="_self"><span>项目文件结构</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/workspace-config" title="&quot;angular.json&quot; 包含供 CLI 命令使用的工作区和项目默认配置。" target="_self"><span>工作区配置</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/npm-packages" title="开发期间和运行期间所需的 npm 包的说明。" target="_self"><span>npm 包</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/typescript-configuration" title="给 Angular 开发者的 TypeScript 配置。" target="_self"><span>TypeScript 配置</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/browser-support" title="浏览器支持与腻子脚本指南。" target="_self"><span>浏览器支持</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-1 collapsed ng-star-inserted" title="Angular 的版本发布实践、更新与升级。" aria-pressed="false"><span>发布信息</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-1 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/updating" title="如何把 Angular 应用和库升级到最新版本。" target="_self"><span>保持最新</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/releases" title="Angular 的版本、发布、支持、弃用策略及实践。" target="_self"><span>发布实践</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/updating-to-version-9" title="支持把你的应用从 8 升级到 9。" target="_self"><span>升级到第 9 版</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/deprecations" title="弃用的 Angular API 和特性汇总。" target="_self"><span>弃用清单</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/ivy" title="关于 Angular Ivy 的编译与渲染管道。" target="_self"><span>Angular Ivy</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-1 collapsed ng-star-inserted" title="Angular 语法、编码、术语汇总。" aria-pressed="false"><span>快捷手册</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-1 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/cheatsheet" title="关于 Angular 常用编码技术的快速指南。" target="_self"><span>速查表</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/styleguide" title="写出 Angular 风格的程序" target="_self"><span>风格指南</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/glossary" title="Angular 中最重要的词汇的简要定义。" target="_self"><span>词汇表</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-1 collapsed ng-star-inserted" title="Angular CLI 命令参考手册。" aria-pressed="false"><span>CLI 命令</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-1 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli" title="CLI 工具介绍、命令、语法" target="_self"><span>概览</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/usage-analytics-gathering" title="管理员如何从用户那里收集使用情况分析。" target="_self"><span>使用情况分析</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/add" title="ng add." target="_self"><span>ng add</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/analytics" title="ng analytics." target="_self"><span>ng analytics</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/build" title="ng build." target="_self"><span>ng build</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/config" title="ng config." target="_self"><span>ng config</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/deploy" title="ng deploy." target="_self"><span>ng deploy</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/doc" title="ng doc." target="_self"><span>ng doc</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/e2e" title="ng e2e." target="_self"><span>ng e2e</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/generate" title="ng generate." target="_self"><span>ng generate</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/help" title="ng help." target="_self"><span>ng help</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/lint" title="ng lint." target="_self"><span>ng lint</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/new" title="ng new." target="_self"><span>ng new</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/run" title="ng run." target="_self"><span>ng run</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/serve" title="ng serve." target="_self"><span>ng serve</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/test" title="ng test." target="_self"><span>ng test</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/update" title="ng update." target="_self"><span>ng update</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/version" title="ng version." target="_self"><span>ng version</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/xi18n" title="ng xi18n." target="_self"><span>ng xi18n</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-1 collapsed ng-star-inserted" style="position:relative" href="api" title="关于 Angular 中类和值的详细信息。" target="_self"><span>API 参考手册</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><div class="mat-divider ng-star-inserted" style="margin:4px 20px;border-top:1px solid #d3d3d3"></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-1 collapsed ng-star-inserted" style="position:relative" href="https://github.com/ng-docs/ng-docs.github.io/issues" title="github 上的中文互助问答区" target="_blank"><span>互助问答</span><mat-icon role="img" class="mat-icon notranslate material-icons mat-icon-no-color ng-star-inserted" aria-hidden="true">open_in_new</mat-icon></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-1 collapsed ng-star-inserted" style="position:relative" href="https://material.angular.cn" title="Angular Material 组件库的中文文档" target="_blank"><span>官方 Material 组件库</span><mat-icon role="img" class="mat-icon notranslate material-icons mat-icon-no-color ng-star-inserted" aria-hidden="true">open_in_new</mat-icon></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-1 collapsed ng-star-inserted" style="position:relative" href="https://ng.ant.design/" title="Ant Design 的 Angular 实现，服务于企业级后台产品。" target="_blank"><span>ng-zorro 组件库</span><mat-icon role="img" class="mat-icon notranslate material-icons mat-icon-no-color ng-star-inserted" aria-hidden="true">open_in_new</mat-icon></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-1 collapsed ng-star-inserted" style="position:relative" href="https://ng.mobile.ant.design/" title="Ant Design Mobile 的 Angular 实现，服务于无线产品。" target="_blank"><span>ng-zorro mobile 组件库</span><mat-icon role="img" class="mat-icon notranslate material-icons mat-icon-no-color ng-star-inserted" aria-hidden="true">open_in_new</mat-icon></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-1 collapsed ng-star-inserted" style="position:relative" href="https://flutter-io.cn/" title="Flutter 中文文档站" target="_blank"><span>友站：Flutter 中文</span><mat-icon role="img" class="mat-icon notranslate material-icons mat-icon-no-color ng-star-inserted" aria-hidden="true">open_in_new</mat-icon></a></div></aio-nav-item></aio-nav-menu><div class="doc-version ng-tns-c18-1"><aio-select><div class="form-select-menu"><button class="form-select-button"><span><strong></strong></span><span>stable (v9.0.0)</span></button></div></aio-select></div></div></mat-sidenav><div class="cdk-visually-hidden cdk-focus-trap-anchor" aria-hidden="true"></div><mat-sidenav-content cdkscrollable="" class="mat-drawer-content mat-sidenav-content ng-star-inserted" style="margin-left:261px"><main role="main" class="sidenav-content" id="guide-reactive-forms"><aio-mode-banner></aio-mode-banner><aio-doc-viewer class=""><div style="opacity:1"><div class="github-links"><a href="https://github.com/angular/angular-cn/edit/aio/aio/content/guide/reactive-forms.md?message=docs%3A%20请简述你的修改..." aria-label="提供编辑建议" title="提供编辑建议"><i class="material-icons" aria-hidden="true" role="img">mode_edit</i></a></div><div class="content"><h1 id="reactive-forms" translation-result="on">响应式表单<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#reactive-forms"><i class="material-icons">link</i></a></h1><aio-toc class="embedded" ng-version="9.0.0-rc.11"><div class="toc-inner no-print collapsed ng-star-inserted"><button type="button" title="Expand/collapse contents" aria-label="Expand/collapse contents" class="toc-heading embedded secondary ng-star-inserted" aria-pressed="false">目录<mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon collapsed mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><ul class="toc-list embedded"><li class="h2 ng-star-inserted" title="响应式表单简介"><a href="guide/reactive-forms#introduction-to-reactive-forms">响应式表单简介</a></li><li class="h2 ng-star-inserted" title="快速上手"><a href="guide/reactive-forms#getting-started">快速上手</a></li><li class="h3 ng-star-inserted" title="步骤 1 - 注册 ReactiveFormsModule"><a href="guide/reactive-forms#step-1-registering-the-reactive-forms-module">步骤 1 - 注册 <code>ReactiveFormsModule</code></a></li><li class="h3 secondary ng-star-inserted" title="步骤 2 - 生成并导入一个新的表单控件"><a href="guide/reactive-forms#step-2-generating-and-importing-a-new-form-control">步骤 2 - 生成并导入一个新的表单控件</a></li><li class="h3 secondary ng-star-inserted" title="步骤 3 - 在模板中注册该控件"><a href="guide/reactive-forms#step-3-registering-the-control-in-the-template">步骤 3 - 在模板中注册该控件</a></li><li class="h2 secondary ng-star-inserted" title="管理控件的值"><a href="guide/reactive-forms#managing-control-values">管理控件的值</a></li><li class="h3 secondary ng-star-inserted" title="显示表单控件的值"><a href="guide/reactive-forms#displaying-a-form-control-value">显示表单控件的值</a></li><li class="h3 secondary ng-star-inserted" title="替换表单控件的值"><a href="guide/reactive-forms#replacing-a-form-control-value">替换表单控件的值</a></li><li class="h2 secondary ng-star-inserted" title="把表单控件分组"><a href="guide/reactive-forms#grouping-form-controls">把表单控件分组</a></li><li class="h3 secondary ng-star-inserted" title="步骤 1 - 创建 FormGroup 实例"><a href="guide/reactive-forms#step-1-creating-a-formgroup-instance">步骤 1 - 创建 <code>FormGroup</code> 实例</a></li><li class="h3 secondary ng-star-inserted" title="步骤 2 - 关联 FormGroup 的模型和视图"><a href="guide/reactive-forms#step-2-associating-the-formgroup-model-and-view">步骤 2 - 关联 <code>FormGroup</code> 的模型和视图</a></li><li class="h3 secondary ng-star-inserted" title="保存表单数据"><a href="guide/reactive-forms#saving-form-data">保存表单数据</a></li><li class="h2 secondary ng-star-inserted" title="嵌套的表单组"><a href="guide/reactive-forms#creating-nested-form-groups">嵌套的表单组</a></li><li class="h3 secondary ng-star-inserted" title="步骤 1 - 创建嵌套的分组"><a href="guide/reactive-forms#step-1-creating-a-nested-group">步骤 1 - 创建嵌套的分组</a></li><li class="h3 secondary ng-star-inserted" title="步骤 2 - 在模板中分组内嵌的表单"><a href="guide/reactive-forms#step-2-grouping-the-nested-form-in-the-template">步骤 2 - 在模板中分组内嵌的表单</a></li><li class="h2 secondary ng-star-inserted" title="部分模型更新"><a href="guide/reactive-forms#partial-model-updates">部分模型更新</a></li><li class="h3 secondary ng-star-inserted" title="修补（Patching）模型值"><a href="guide/reactive-forms#patching-the-model-value">修补（Patching）模型值</a></li><li class="h2 secondary ng-star-inserted" title="使用 FormBuilder 来生成表单控件"><a href="guide/reactive-forms#generating-form-controls-with-formbuilder">使用 <code>FormBuilder</code> 来生成表单控件</a></li><li class="h3 secondary ng-star-inserted" title="步骤 1 - 导入 FormBuilder 类"><a href="guide/reactive-forms#step-1-importing-the-formbuilder-class">步骤 1 - 导入 <code>FormBuilder</code> 类</a></li><li class="h3 secondary ng-star-inserted" title="步骤 2 - 注入 FormBuilder 服务"><a href="guide/reactive-forms#step-2-injecting-the-formbuilder-service">步骤 2 - 注入 <code>FormBuilder</code> 服务</a></li><li class="h3 secondary ng-star-inserted" title="步骤 3 - 生成表单控件"><a href="guide/reactive-forms#step-3-generating-form-controls">步骤 3 - 生成表单控件</a></li><li class="h2 secondary ng-star-inserted" title="简单表单验证"><a href="guide/reactive-forms#simple-form-validation">简单表单验证</a></li><li class="h3 secondary ng-star-inserted" title="步骤 1 - 导入验证器函数"><a href="guide/reactive-forms#step-1-importing-a-validator-function">步骤 1 - 导入验证器函数</a></li><li class="h3 secondary ng-star-inserted" title="步骤 2 - 把字段设为必填（required）"><a href="guide/reactive-forms#step-2-making-a-field-required">步骤 2 - 把字段设为必填（required）</a></li><li class="h3 secondary ng-star-inserted" title="显示表单状态"><a href="guide/reactive-forms#displaying-form-status">显示表单状态</a></li><li class="h2 secondary ng-star-inserted" title="使用表单数组管理动态控件"><a href="guide/reactive-forms#dynamic-controls-using-form-arrays">使用表单数组管理动态控件</a></li><li class="h3 secondary ng-star-inserted" title="步骤 1 - 导入 FormArray"><a href="guide/reactive-forms#step-1-importing-the-formarray-class">步骤 1 - 导入 <code>FormArray</code></a></li><li class="h3 secondary ng-star-inserted" title="步骤 2 - 定义 FormArray"><a href="guide/reactive-forms#step-2-defining-a-formarray-control">步骤 2 - 定义 <code>FormArray</code></a></li><li class="h3 secondary ng-star-inserted" title="步骤 3 - 访问 FormArray 控件"><a href="guide/reactive-forms#step-3-accessing-the-formarray-control">步骤 3 - 访问 <code>FormArray</code> 控件</a></li><li class="h3 secondary ng-star-inserted" title="步骤 4 - 在模板中显示表单数组"><a href="guide/reactive-forms#step-4-displaying-the-form-array-in-the-template">步骤 4 - 在模板中显示表单数组</a></li><li class="h2 secondary ng-star-inserted" title="附录"><a href="guide/reactive-forms#appendix">附录</a></li><li class="h3 secondary ng-star-inserted" title="响应式表单 API"><a href="guide/reactive-forms#reactive-forms-api">响应式表单 API</a></li></ul><button type="button" title="Expand/collapse contents" aria-label="Expand/collapse contents" class="toc-more-items embedded material-icons collapsed ng-star-inserted" aria-pressed="false"></button></div></aio-toc><h1 translation-origin="off" id="reactive-forms">Reactive forms<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#reactive-forms"><i class="material-icons">link</i></a></h1><p translation-result="on"><em>响应式表单</em>提供了一种模型驱动的方式来处理表单输入，其中的值会随时间而变化。本文会向你展示如何创建和更新单个表单控件，然后在一个分组中使用多个控件，验证表单的值，以及如何实现更高级的表单。</p><p translation-origin="off"><em>Reactive forms</em> provide a model-driven approach to handling form inputs whose values change over time. This guide shows you how to create and update a simple form control, progress to using multiple controls in a group, validate form values, and implement more advanced forms.</p><a id="toc"></a><p translation-result="on">试试<live-example title="Reactive Forms in Stackblitz" ng-version="9.0.0-rc.11"><span style="display:none">响应式表单的在线例子</span><span><span class="ng-star-inserted"><a target="_blank" title="响应式表单的在线例子" href="generated/live-examples/reactive-forms/stackblitz.html">响应式表单的在线例子</a><span class="ng-star-inserted"> / <a download="" title="下载范例" href="generated/zips/reactive-forms/reactive-forms.zip">下载范例</a></span></span></span></live-example>。</p><p translation-origin="off">Try the<live-example title="Reactive Forms in Stackblitz" ng-version="9.0.0-rc.11"><span style="display:none">Reactive Forms live-example</span><span><span class="ng-star-inserted"><a target="_blank" title="Reactive Forms live-example" href="generated/live-examples/reactive-forms/stackblitz.html">Reactive Forms live-example</a><span class="ng-star-inserted"> / <a download="" title="下载范例" href="generated/zips/reactive-forms/reactive-forms.zip">下载范例</a></span></span></span></live-example>.</p><a id="intro"></a><h2 id="introduction-to-reactive-forms" translation-result="on">响应式表单简介<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#introduction-to-reactive-forms"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="introduction-to-reactive-forms">Introduction to reactive forms<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#introduction-to-reactive-forms"><i class="material-icons">link</i></a></h2><p translation-result="on">响应式表单使用显式的、不可变的方式，管理表单在特定的时间点上的状态。对表单状态的每一次变更都会返回一个新的状态，这样可以在变化时维护模型的整体性。响应式表单是围绕 Observable 的流构建的，表单的输入和值都是通过这些输入值组成的流来提供的，它可以同步访问。</p><p translation-origin="off">Reactive forms use an explicit and immutable approach to managing the state of a form at a given point in time. Each change to the form state returns a new state, which maintains the integrity of the model between changes. Reactive forms are built around observable streams, where form inputs and values are provided as streams of input values, which can be accessed synchronously.</p><p translation-result="on">响应式表单还提供了一种更直观的测试路径，因为在请求时你可以确信这些数据是一致的、可预料的。这个流的任何一个消费者都可以安全地操纵这些数据。</p><p translation-origin="off">Reactive forms also provide a straightforward path to testing because you are assured that your data is consistent and predictable when requested. Any consumers of the streams have access to manipulate that data safely.</p><p translation-result="on">响应式表单与模板驱动的表单有着显著的不同点。响应式表单通过对数据模型的同步访问提供了更多的可预测性，使用 Observable 的操作符提供了不可变性，并且通过 Observable 流提供了变化追踪功能。 如果你更喜欢在模板中直接访问数据，那么模板驱动的表单会显得更明确，因为它们依赖嵌入到模板中的指令，并借助可变数据来异步跟踪变化。参见<a href="guide/forms-overview">表单概览</a>来了解这两种范式之间的详细比较。</p><p translation-origin="off">Reactive forms differ from template-driven forms in distinct ways. Reactive forms provide more predictability with synchronous access to the data model, immutability with observable operators, and change tracking through observable streams. If you prefer direct access to modify data in your template, template-driven forms are less explicit because they rely on directives embedded in the template, along with mutable data to track changes asynchronously. See the <a href="guide/forms-overview">Forms Overview</a> for detailed comparisons between the two paradigms.</p><h2 id="getting-started" translation-result="on">快速上手<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#getting-started"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="getting-started">Getting started<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#getting-started"><i class="material-icons">link</i></a></h2><p translation-result="on">本节描述了如何添加单个表单控件。这里的例子允许用户在输入框中输入自己的名字，捕获输入的值，并把表单控件元素的当前值显示出来。</p><p translation-origin="off">This section describes how to add a single form control. In the example, the user enters their name into an input field, captures that input value, and displays the current value of the form control element.</p><h3 id="step-1-registering-the-reactive-forms-module" translation-result="on">步骤 1 - 注册 <code><a href="api/forms/ReactiveFormsModule" class="code-anchor">ReactiveFormsModule</a></code><a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-1-registering-the-reactive-forms-module"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="step-1-registering-the-reactive-forms-module">Step 1: Registering the reactive forms module<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-1-registering-the-reactive-forms-module"><i class="material-icons">link</i></a></h3><p translation-result="on">要使用响应式表单，就要从 <code>@angular/forms</code> 包中导入 <code><a href="api/forms/ReactiveFormsModule" class="code-anchor">ReactiveFormsModule</a></code> 并把它添加到你的 NgModule 的 <code>imports</code> 数组中。</p><p translation-origin="off">To use reactive forms, import <code><a href="api/forms/ReactiveFormsModule" class="code-anchor">ReactiveFormsModule</a></code> from the <code>@angular/forms</code> package and add it to your NgModule's <code>imports</code> array.</p><code-example path="reactive-forms/src/app/app.module.ts" region="imports" header="src/app/app.module.ts (excerpt)" ng-version="9.0.0-rc.11"><div style="display:none">import { <a href="api/forms/ReactiveFormsModule" class="code-anchor">ReactiveFormsModule</a> } from '@angular/forms'; @<a href="api/core/NgModule" class="code-anchor">NgModule</a>({ imports: [ // other imports ... <a href="api/forms/ReactiveFormsModule" class="code-anchor">ReactiveFormsModule</a> ], }) export class AppModule { }</div><header class="ng-star-inserted">src/app/app.module.ts (excerpt)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app.module.ts (excerpt)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/forms/ReactiveFormsModule" class="code-anchor"><span class="typ">ReactiveFormsModule</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/forms'</span><span class="pun">;</span><span class="pln">

</span><span class="lit">@</span><a href="api/core/NgModule" class="code-anchor"><span class="lit">NgModule</span></a><span class="pun">({</span><span class="pln">
  imports</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="pln">
    </span><span class="com">// other imports ...</span><span class="pln">
    </span><a href="api/forms/ReactiveFormsModule" class="code-anchor"><span class="typ">ReactiveFormsModule</span></a><span class="pln">
  </span><span class="pun">],</span><span class="pln">
</span><span class="pun">})</span><span class="pln">
</span><span class="kwd">export</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">AppModule</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="pun">}</span></code>
    </pre></aio-code></code-example><h3 id="step-2-generating-and-importing-a-new-form-control" translation-result="on">步骤 2 - 生成并导入一个新的表单控件<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-2-generating-and-importing-a-new-form-control"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="step-2-generating-and-importing-a-new-form-control">Step 2: Generating and importing a new form control<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-2-generating-and-importing-a-new-form-control"><i class="material-icons">link</i></a></h3><p translation-result="on">为该控件生成一个组件。</p><p translation-origin="off">Generate a component for the control.</p><code-example language="sh" class="code-shell" ng-version="9.0.0-rc.11"><div style="display:none">ng generate component NameEditor</div><aio-code><pre class="lang-sh prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">ng generate component </span><span class="typ">NameEditor</span></code>
    </pre></aio-code></code-example><p translation-result="on">当使用响应式表单时，<code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 类是最基本的构造块。要注册单个的表单控件，请在组件中导入 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 类，并创建一个 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 的新实例，把它保存在类的某个属性中。</p><p translation-origin="off">The <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> class is the basic building block when using reactive forms. To register a single form control, import the <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> class into your component and create a new instance of the form control to save as a class property.</p><code-example path="reactive-forms/src/app/name-editor/name-editor.component.ts" region="create-control" header="src/app/name-editor/name-editor.component.ts" ng-version="9.0.0-rc.11"><div style="display:none">import { <a href="api/core/Component" class="code-anchor">Component</a> } from '@angular/core'; import { <a href="api/forms/FormControl" class="code-anchor">FormControl</a> } from '@angular/forms'; @<a href="api/core/Component" class="code-anchor">Component</a>({ selector: 'app-name-editor', <a href="api/core/Component#templateUrl" class="code-anchor">templateUrl</a>: './name-editor.component.html', <a href="api/core/Component#styleUrls" class="code-anchor">styleUrls</a>: ['./name-editor.component.css'] }) export class NameEditorComponent { name = new <a href="api/forms/FormControl" class="code-anchor">FormControl</a>(''); }</div><header class="ng-star-inserted">src/app/name-editor/name-editor.component.ts</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/name-editor/name-editor.component.ts">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/core/Component" class="code-anchor"><span class="typ">Component</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/core'</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/forms'</span><span class="pun">;</span><span class="pln">

</span><span class="lit">@</span><a href="api/core/Component" class="code-anchor"><span class="lit">Component</span></a><span class="pun">({</span><span class="pln">
  selector</span><span class="pun">:</span><span class="pln"> </span><span class="str">'app-name-editor'</span><span class="pun">,</span><span class="pln">
  </span><a href="api/core/Component#templateUrl" class="code-anchor"><span class="pln">templateUrl</span></a><span class="pun">:</span><span class="pln"> </span><span class="str">'./name-editor.component.html'</span><span class="pun">,</span><span class="pln">
  </span><a href="api/core/Component#styleUrls" class="code-anchor"><span class="pln">styleUrls</span></a><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">'./name-editor.component.css'</span><span class="pun">]</span><span class="pln">
</span><span class="pun">})</span><span class="pln">
</span><span class="kwd">export</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">NameEditorComponent</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  name </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pun">(</span><span class="str">''</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span></code>
    </pre></aio-code></code-example><p translation-result="on">可以用 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 的构造函数设置初始值，这个例子中它是空字符串。通过在你的组件类中创建这些控件，你可以直接对表单控件的状态进行监听、修改和校验。</p><p translation-origin="off">Use the constructor of <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> to set its initial value, which in this case is an empty string. By creating these controls in your component class, you get immediate access to listen for, update, and validate the state of the form input.</p><h3 id="step-3-registering-the-control-in-the-template" translation-result="on">步骤 3 - 在模板中注册该控件<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-3-registering-the-control-in-the-template"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="step-3-registering-the-control-in-the-template">Step 3: Registering the control in the template<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-3-registering-the-control-in-the-template"><i class="material-icons">link</i></a></h3><p translation-result="on">在组件类中创建了控件之后，你还要把它和模板中的一个表单控件关联起来。修改模板，为表单控件添加 <code>formControl</code> 绑定，<code>formControl</code> 是由 <code><a href="api/forms/ReactiveFormsModule" class="code-anchor">ReactiveFormsModule</a></code> 中的 <code><a href="api/forms/FormControlDirective" class="code-anchor">FormControlDirective</a></code> 提供的。</p><p translation-origin="off">After you create the control in the component class, you must associate it with a form control element in the template. Update the template with the form control using the <code>formControl</code> binding provided by <code><a href="api/forms/FormControlDirective" class="code-anchor">FormControlDirective</a></code> included in <code><a href="api/forms/ReactiveFormsModule" class="code-anchor">ReactiveFormsModule</a></code>.</p><code-example path="reactive-forms/src/app/name-editor/name-editor.component.html" region="control-binding" header="src/app/name-editor/name-editor.component.html" ng-version="9.0.0-rc.11"><div style="display:none">&lt;label&gt; Name: &lt;input type="text" [formControl]="name"&gt; &lt;/label&gt;</div><header class="ng-star-inserted">src/app/name-editor/name-editor.component.html</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/name-editor/name-editor.component.html">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;label&gt;</span><span class="pln">
  Name:
  </span><span class="tag">&lt;input</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text"</span><span class="pln"> [</span><span class="atn">formControl</span><span class="pln">]</span><span class="pun">=</span><span class="atv">"name"</span><span class="tag">&gt;</span><span class="pln">
</span><span class="tag">&lt;/label&gt;</span></code>
    </pre></aio-code></code-example><div class="alert is-helpful"><p translation-result="on"><em>注意</em>：要了解 <code><a href="api/forms/ReactiveFormsModule" class="code-anchor">ReactiveFormsModule</a></code> 提供的更多类和指令，请参见 <a href="guide/reactive-forms#reactive-forms-api">响应式表单 API</a> 一节。</p><p translation-origin="off"><strong>Note:</strong> For a more detailed list of classes and directives provided by <code><a href="api/forms/ReactiveFormsModule" class="code-anchor">ReactiveFormsModule</a></code>, see the <a href="guide/reactive-forms#reactive-forms-api">Reactive forms API</a> section.</p></div><p translation-result="on">使用这种模板绑定语法，把该表单控件注册给了模板中名为 <code>name</code> 的输入元素。这样，表单控件和 DOM 元素就可以互相通讯了：视图会反映模型的变化，模型也会反映视图中的变化。</p><p translation-origin="off">Using the template binding syntax, the form control is now registered to the <code>name</code> input element in the template. The form control and DOM element communicate with each other: the view reflects changes in the model, and the model reflects changes in the view.</p><h4 id="displaying-the-component" translation-result="on">显示组件<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#displaying-the-component"><i class="material-icons">link</i></a></h4><h4 translation-origin="off" id="displaying-the-component">Displaying the component<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#displaying-the-component"><i class="material-icons">link</i></a></h4><p translation-result="on">把该组件添加到模板时，将显示指派给 <code>name</code> 的表单控件。</p><p translation-origin="off">The form control assigned to <code>name</code> is displayed when the component is added to a template.</p><code-example path="reactive-forms/src/app/app.component.1.html" region="app-name-editor" header="src/app/app.component.html (name editor)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;app-name-editor&gt;&lt;/app-name-editor&gt;</div><header class="ng-star-inserted">src/app/app.component.html (name editor)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app.component.html (name editor)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;app-name-editor&gt;&lt;/app-name-editor&gt;</span></code>
    </pre></aio-code></code-example><div class="lightbox"><img src="generated/images/guide/reactive-forms/name-editor-1.png" alt="Name Editor" width="352" height="84"></div><h2 id="managing-control-values" translation-result="on">管理控件的值<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#managing-control-values"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="managing-control-values">Managing control values<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#managing-control-values"><i class="material-icons">link</i></a></h2><p translation-result="on">响应式表单让你可以访问表单控件此刻的状态和值。你可以通过组件类或组件模板来操纵其当前状态和值。下面的例子会显示及修改 <code>FormConrol</code> 实例的值。</p><p translation-origin="off">Reactive forms give you access to the form control state and value at a point in time. You can manipulate the current state and value through the component class or the component template. The following examples display the value of the form control instance and change it.</p><a id="display-value"></a><h3 id="displaying-a-form-control-value" translation-result="on">显示表单控件的值<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#displaying-a-form-control-value"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="displaying-a-form-control-value">Displaying a form control value<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#displaying-a-form-control-value"><i class="material-icons">link</i></a></h3><p translation-result="on">你可以用两种方式显示它的值：</p><p translation-origin="off">You can display the value in these ways:</p><ul><li><p translation-result="on">通过可观察对象 <code>valueChanges</code>，你可以在模板中使用 <code><a href="api/common/AsyncPipe" class="code-anchor">AsyncPipe</a></code> 或在组件类中使用 <code>subscribe()</code> 方法来监听表单值的变化。</p><p translation-origin="off">Through the <code>valueChanges</code> observable where you can listen for changes in the form's value in the template using <code><a href="api/common/AsyncPipe" class="code-anchor">AsyncPipe</a></code> or in the component class using the <code>subscribe()</code> method.</p></li><li><p translation-result="on">使用 <code>value</code> 属性。它能让你获得当前值的一份快照。</p><p translation-origin="off">With the <code>value</code> property, which gives you a snapshot of the current value.</p></li></ul><p translation-result="on">下面的例子展示了如何在模板中使用插值显示当前值。</p><p translation-origin="off">The following example shows you how to display the current value using interpolation in the template.</p><code-example path="reactive-forms/src/app/name-editor/name-editor.component.html" region="display-value" header="src/app/name-editor/name-editor.component.html (control value)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;p&gt; Value: {{ name.value }} &lt;/p&gt;</div><header class="ng-star-inserted">src/app/name-editor/name-editor.component.html (control value)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/name-editor/name-editor.component.html (control value)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;p&gt;</span><span class="pln">
  Value: {{ name.value }}
</span><span class="tag">&lt;/p&gt;</span></code>
    </pre></aio-code></code-example><p translation-result="on">一旦你修改了表单控件所关联的元素，这里显示的值也跟着变化了。</p><p translation-origin="off">The displayed value changes as you update the form control element.</p><p translation-result="on">响应式表单还能通过每个实例的属性和方法提供关于特定控件的更多信息。<a href="api/forms/AbstractControl">AbstractControl</a> 的这些属性和方法用于控制表单状态，并在处理表单校验时决定何时显示信息。 欲知详情，参见稍后的<a href="guide/reactive-forms#simple-form-validation">简单表单验证</a>一节。</p><p translation-origin="off">Reactive forms provide access to information about a given control through properties and methods provided with each instance. These properties and methods of the underlying <a href="api/forms/AbstractControl">AbstractControl</a> class are used to control form state and determine when to display messages when handling validation. For more information, see <a href="guide/reactive-forms#simple-form-validation">Simple form validation</a> later in this guide.</p><p translation-result="on">要了解 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 的其它属性和方法，参见<a href="guide/reactive-forms#reactive-forms-api">响应式表单 API</a>一节。</p><p translation-origin="off">Read about other <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> properties and methods in the <a href="guide/reactive-forms#reactive-forms-api">Reactive forms API</a> section.</p><h3 id="replacing-a-form-control-value" translation-result="on">替换表单控件的值<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#replacing-a-form-control-value"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="replacing-a-form-control-value">Replacing a form control value<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#replacing-a-form-control-value"><i class="material-icons">link</i></a></h3><p translation-result="on">响应式表单还有一些方法可以用编程的方式修改控件的值，它让你可以灵活的修改控件的值而不需要借助用户交互。<code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 提供了一个 <code>setValue()</code> 方法，它会修改这个表单控件的值，并且验证与控件结构相对应的值的结构。比如，当从后端 API 或服务接收到了表单数据时，可以通过 <code>setValue()</code> 方法来把原来的值替换为新的值。</p><p translation-origin="off">Reactive forms have methods to change a control's value programmatically, which gives you the flexibility to update the value without user interaction. A form control instance provides a <code>setValue()</code> method that updates the value of the form control and validates the structure of the value provided against the control's structure. For example, when retrieving form data from a backend API or service, use the <code>setValue()</code> method to update the control to its new value, replacing the old value entirely.</p><p translation-result="on">下列的例子往组件类中添加了一个方法，它使用 <code>setValue()</code> 方法来修改 <em>Nancy</em> 控件的值。</p><p translation-origin="off">The following example adds a method to the component class to update the value of the control to <em>Nancy</em> using the <code>setValue()</code> method.</p><code-example path="reactive-forms/src/app/name-editor/name-editor.component.ts" region="update-value" header="src/app/name-editor/name-editor.component.ts (update value)" ng-version="9.0.0-rc.11"><div style="display:none">updateName() { this.name.setValue('Nancy'); }</div><header class="ng-star-inserted">src/app/name-editor/name-editor.component.ts (update value)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/name-editor/name-editor.component.ts (update value)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">updateName</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">name</span><span class="pun">.</span><span class="pln">setValue</span><span class="pun">(</span><span class="str">'Nancy'</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span></code>
    </pre></aio-code></code-example><p translation-result="on">修改模板，添加一个按钮，用于模拟改名操作。在点 <code><a href="" class="code-anchor">Update</a> Name</code> 按钮之前表单控件元素中输入的任何值都会回显为它的当前值。</p><p translation-origin="off">Update the template with a button to simulate a name update. When you click the <strong>Update Name</strong> button, the value entered in the form control element is reflected as its current value.</p><code-example path="reactive-forms/src/app/name-editor/name-editor.component.html" region="update-value" header="src/app/name-editor/name-editor.component.html (update value)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;p&gt; &lt;button (click)="updateName()"&gt;<a href="" class="code-anchor">Update</a> Name&lt;/button&gt; &lt;/p&gt;</div><header class="ng-star-inserted">src/app/name-editor/name-editor.component.html (update value)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/name-editor/name-editor.component.html (update value)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;p&gt;</span><span class="pln">
  </span><span class="tag">&lt;button</span><span class="pln"> (</span><span class="atn">click</span><span class="pln">)</span><span class="pun">=</span><span class="atv">"updateName()"</span><span class="tag">&gt;</span><a href="" class="code-anchor"><span class="pln">Update</span></a><span class="pln"> Name</span><span class="tag">&lt;/button&gt;</span><span class="pln">
</span><span class="tag">&lt;/p&gt;</span></code>
    </pre></aio-code></code-example><p translation-result="on">由于表单模型是该控件的权威数据源，因此当你单击该按钮时，组件中该输入框的值也变化了，覆盖掉它的当前值。</p><p translation-origin="off">The form model is the source of truth for the control, so when you click the button, the value of the input is changed within the component class, overriding its current value.</p><div class="lightbox"><img src="generated/images/guide/reactive-forms/name-editor-2.png" alt="Name Editor Update" width="352" height="182"></div><div class="alert is-helpful"><p translation-result="on"><em>注意</em>：在这个例子中，你只使用单个控件，但是当调用 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 或 <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> 的 <code>setValue()</code> 方法时，传入的值就必须匹配控件组或控件数组的结构才行。</p><p translation-origin="off"><strong>Note:</strong> In this example, you're using a single control. When using the <code>setValue()</code> method with a form group or form array instance, the value needs to match the structure of the group or array.</p></div><h2 id="grouping-form-controls" translation-result="on">把表单控件分组<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#grouping-form-controls"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="grouping-form-controls">Grouping form controls<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#grouping-form-controls"><i class="material-icons">link</i></a></h2><p translation-result="on">就像 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 的实例能让你控制单个输入框所对应的控件一样，<code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 的实例也能跟踪一组 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 实例（比如一个表单）的表单状态。当创建 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 时，其中的每个控件都会根据其名字进行跟踪。下列例子展示了如何管理单个控件组中的多个 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 实例。</p><p translation-origin="off">Just as a form control instance gives you control over a single input field, a form group instance tracks the form state of a group of form control instances (for example, a form). Each control in a form group instance is tracked by name when creating the form group. The following example shows how to manage multiple form control instances in a single group.</p><p translation-result="on">生成一个 <code>ProfileEditor</code> 组件并从 <code>@angular/forms</code> 包中导入 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 和 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 类。</p><p translation-origin="off">Generate a <code>ProfileEditor</code> component and import the <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> and <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> classes from the <code>@angular/forms</code> package.</p><code-example language="sh" class="code-shell" ng-version="9.0.0-rc.11"><div style="display:none">ng generate component ProfileEditor</div><aio-code><pre class="lang-sh prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">ng generate component </span><span class="typ">ProfileEditor</span></code>
    </pre></aio-code></code-example><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.1.ts" region="imports" header="src/app/profile-editor/profile-editor.component.ts (imports)" ng-version="9.0.0-rc.11"><div style="display:none">import { <a href="api/forms/FormGroup" class="code-anchor">FormGroup</a>, <a href="api/forms/FormControl" class="code-anchor">FormControl</a> } from '@angular/forms';</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.ts (imports)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.ts (imports)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/forms/FormGroup" class="code-anchor"><span class="typ">FormGroup</span></a><span class="pun">,</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/forms'</span><span class="pun">;</span></code>
    </pre></aio-code></code-example><h3 id="step-1-creating-a-formgroup-instance" translation-result="on">步骤 1 - 创建 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 实例<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-1-creating-a-formgroup-instance"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="step-1-creating-a-formgroup-instance">Step 1: Creating a FormGroup instance<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-1-creating-a-formgroup-instance"><i class="material-icons">link</i></a></h3><p translation-result="on">在组件类中创建一个名叫 <code>profileForm</code> 的属性，并设置为 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 的一个新实例。要初始化这个 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code>，请为构造函数提供一个由控件组成的对象，对象中的每个名字都要和表单控件的名字一一对应。</p><p translation-origin="off">Create a property in the component class named <code>profileForm</code> and set the property to a new form group instance. To initialize the form group, provide the constructor with an object of named keys mapped to their control.</p><p translation-result="on">对此个人档案表单，要添加两个 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 实例，名字分别为 <code>firstName</code> 和 <code>lastName</code>。</p><p translation-origin="off">For the profile form, add two form control instances with the names <code>firstName</code> and <code>lastName</code>.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.1.ts" region="formgroup" header="src/app/profile-editor/profile-editor.component.ts (form group)" ng-version="9.0.0-rc.11"><div style="display:none">import { <a href="api/core/Component" class="code-anchor">Component</a> } from '@angular/core'; import { <a href="api/forms/FormGroup" class="code-anchor">FormGroup</a>, <a href="api/forms/FormControl" class="code-anchor">FormControl</a> } from '@angular/forms'; @<a href="api/core/Component" class="code-anchor">Component</a>({ selector: 'app-profile-editor', <a href="api/core/Component#templateUrl" class="code-anchor">templateUrl</a>: './profile-editor.component.html', <a href="api/core/Component#styleUrls" class="code-anchor">styleUrls</a>: ['./profile-editor.component.css'] }) export class ProfileEditorComponent { profileForm = new <a href="api/forms/FormGroup" class="code-anchor">FormGroup</a>({ firstName: new <a href="api/forms/FormControl" class="code-anchor">FormControl</a>(''), lastName: new <a href="api/forms/FormControl" class="code-anchor">FormControl</a>(''), }); }</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.ts (form group)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.ts (form group)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/core/Component" class="code-anchor"><span class="typ">Component</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/core'</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/forms/FormGroup" class="code-anchor"><span class="typ">FormGroup</span></a><span class="pun">,</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/forms'</span><span class="pun">;</span><span class="pln">

</span><span class="lit">@</span><a href="api/core/Component" class="code-anchor"><span class="lit">Component</span></a><span class="pun">({</span><span class="pln">
  selector</span><span class="pun">:</span><span class="pln"> </span><span class="str">'app-profile-editor'</span><span class="pun">,</span><span class="pln">
  </span><a href="api/core/Component#templateUrl" class="code-anchor"><span class="pln">templateUrl</span></a><span class="pun">:</span><span class="pln"> </span><span class="str">'./profile-editor.component.html'</span><span class="pun">,</span><span class="pln">
  </span><a href="api/core/Component#styleUrls" class="code-anchor"><span class="pln">styleUrls</span></a><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">'./profile-editor.component.css'</span><span class="pun">]</span><span class="pln">
</span><span class="pun">})</span><span class="pln">
</span><span class="kwd">export</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">ProfileEditorComponent</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  profileForm </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormGroup" class="code-anchor"><span class="typ">FormGroup</span></a><span class="pun">({</span><span class="pln">
    firstName</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pun">(</span><span class="str">''</span><span class="pun">),</span><span class="pln">
    lastName</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pun">(</span><span class="str">''</span><span class="pun">),</span><span class="pln">
  </span><span class="pun">});</span><span class="pln">
</span><span class="pun">}</span></code>
    </pre></aio-code></code-example><p translation-result="on">现在，这些独立的表单控件被收集到了一个控件组中。这个 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 用对象的形式提供了它的模型值，这个值来自组中每个控件的值。 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 实例拥有和 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 实例相同的属性（比如 <code>value</code>、<code>untouched</code>）和方法（比如 <code>setValue()</code>）。</p><p translation-origin="off">The individual form controls are now collected within a group. A <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> instance provides its model value as an object reduced from the values of each control in the group. A form group instance has the same properties (such as <code>value</code> and <code>untouched</code>) and methods (such as <code>setValue()</code>) as a form control instance.</p><h3 id="step-2-associating-the-formgroup-model-and-view" translation-result="on">步骤 2 - 关联 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 的模型和视图<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-2-associating-the-formgroup-model-and-view"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="step-2-associating-the-formgroup-model-and-view">Step 2: Associating the FormGroup model and view<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-2-associating-the-formgroup-model-and-view"><i class="material-icons">link</i></a></h3><p translation-result="on">这个表单组还能跟踪其中每个控件的状态及其变化，所以如果其中的某个控件的状态或值变化了，父控件也会发出一次新的状态变更或值变更事件。该控件组的模型来自它的所有成员。在定义了这个模型之后，你必须更新模板，来把该模型反映到视图中。</p><p translation-origin="off">A form group tracks the status and changes for each of its controls, so if one of the controls changes, the parent control also emits a new status or value change. The model for the group is maintained from its members. After you define the model, you must update the template to reflect the model in the view.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.1.html" region="formgroup" header="src/app/profile-editor/profile-editor.component.html (template form group)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;form [formGroup]="profileForm"&gt; &lt;label&gt; <a href="" class="code-anchor">First</a> Name: &lt;input type="text" <a href="api/forms/FormControlName" class="code-anchor">formControlName</a>="firstName"&gt; &lt;/label&gt; &lt;label&gt; Last Name: &lt;input type="text" <a href="api/forms/FormControlName" class="code-anchor">formControlName</a>="lastName"&gt; &lt;/label&gt; &lt;/form&gt;</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.html (template form group)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.html (template form group)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;form</span><span class="pln"> [</span><span class="atn">formGroup</span><span class="pln">]</span><span class="pun">=</span><span class="atv">"profileForm"</span><span class="tag">&gt;</span><span class="pln">
  
  </span><span class="tag">&lt;label&gt;</span><span class="pln">
    </span><a href="" class="code-anchor"><span class="pln">First</span></a><span class="pln"> Name:
    </span><span class="tag">&lt;input</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text"</span><span class="pln"> </span><a href="api/forms/FormControlName" class="code-anchor"><span class="atn">formControlName</span></a><span class="pun">=</span><span class="atv">"firstName"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;/label&gt;</span><span class="pln">

  </span><span class="tag">&lt;label&gt;</span><span class="pln">
    Last Name:
    </span><span class="tag">&lt;input</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text"</span><span class="pln"> </span><a href="api/forms/FormControlName" class="code-anchor"><span class="atn">formControlName</span></a><span class="pun">=</span><span class="atv">"lastName"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;/label&gt;</span><span class="pln">

</span><span class="tag">&lt;/form&gt;</span></code>
    </pre></aio-code></code-example><p translation-result="on">注意，就像 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 所包含的那控件一样，<em>profileForm</em> 这个 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 也通过 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 指令绑定到了 <code>form</code> 元素，在该模型和表单中的输入框之间创建了一个通讯层。 由 <code><a href="api/forms/FormControlName" class="code-anchor">FormControlName</a></code> 指令提供的 <code><a href="api/forms/FormControlName" class="code-anchor">formControlName</a></code> 属性把每个输入框和 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 中定义的表单控件绑定起来。这些表单控件会和相应的元素通讯，它们还把更改传给 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code>，这个 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 是模型值的权威数据源。</p><p translation-origin="off">Note that just as a form group contains a group of controls, the <em>profile form</em> <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> is bound to the <code>form</code> element with the <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> directive, creating a communication layer between the model and the form containing the inputs. The <code><a href="api/forms/FormControlName" class="code-anchor">formControlName</a></code> input provided by the <code><a href="api/forms/FormControlName" class="code-anchor">FormControlName</a></code> directive binds each individual input to the form control defined in <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code>. The form controls communicate with their respective elements. They also communicate changes to the form group instance, which provides the source of truth for the model value.</p><h3 id="saving-form-data" translation-result="on">保存表单数据<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#saving-form-data"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="saving-form-data">Saving form data<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#saving-form-data"><i class="material-icons">link</i></a></h3><p translation-result="on"><code>ProfileEditor</code> 组件从用户那里获得输入，但在真实的场景中，你可能想要先捕获表单的值，等将来在组件外部进行处理。 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 指令会监听 <code>form</code> 元素发出的 <code>submit</code> 事件，并发出一个 <code>ngSubmit</code> 事件，让你可以绑定一个回调函数。</p><p translation-origin="off">The <code>ProfileEditor</code> component accepts input from the user, but in a real scenario you want to capture the form value and make available for further processing outside the component. The <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> directive listens for the <code>submit</code> event emitted by the <code>form</code> element and emits an <code>ngSubmit</code> event that you can bind to a callback function.</p><p translation-result="on">把 <code>onSubmit()</code> 回调方法添加为 <code>form</code> 标签上的 <code>ngSubmit</code> 事件监听器。</p><p translation-origin="off">Add an <code>ngSubmit</code> event listener to the <code>form</code> tag with the <code>onSubmit()</code> callback method.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.html" region="ng-submit" header="src/app/profile-editor/profile-editor.component.html (submit event)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;form [formGroup]="profileForm" (ngSubmit)="onSubmit()"&gt;</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.html (submit event)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.html (submit event)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;form</span><span class="pln"> [</span><span class="atn">formGroup</span><span class="pln">]</span><span class="pun">=</span><span class="atv">"profileForm"</span><span class="pln"> (</span><span class="atn">ngSubmit</span><span class="pln">)</span><span class="pun">=</span><span class="atv">"onSubmit()"</span><span class="tag">&gt;</span></code>
    </pre></aio-code></code-example><p translation-result="on"><code>ProfileEditor</code> 组件上的 <code>onSubmit()</code> 方法会捕获 <code>profileForm</code> 的当前值。要保持该表单的封装性，就要使用 <code><a href="api/core/EventEmitter" class="code-anchor">EventEmitter</a></code> 向组件外部提供该表单的值。下面的例子会使用 <code>console.warn</code> 把这个值记录到浏览器的控制台中。</p><p translation-origin="off">The <code>onSubmit()</code> method in the <code>ProfileEditor</code> component captures the current value of <code>profileForm</code>. Use <code><a href="api/core/EventEmitter" class="code-anchor">EventEmitter</a></code> to keep the form encapsulated and to provide the form value outside the component. The following example uses <code>console.warn</code> to log a message to the browser console.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.ts" region="on-submit" header="src/app/profile-editor/profile-editor.component.ts (submit method)" ng-version="9.0.0-rc.11"><div style="display:none">onSubmit() { // TODO: Use <a href="api/core/EventEmitter" class="code-anchor">EventEmitter</a> with form value console.warn(this.profileForm.value); }</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.ts (submit method)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.ts (submit method)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">onSubmit</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  </span><span class="com">// TODO: Use </span><a href="api/core/EventEmitter" class="code-anchor"><span class="com">EventEmitter</span></a><span class="com"> with form value</span><span class="pln">
  console</span><span class="pun">.</span><span class="pln">warn</span><span class="pun">(</span><span class="kwd">this</span><span class="pun">.</span><span class="pln">profileForm</span><span class="pun">.</span><span class="kwd">value</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span></code>
    </pre></aio-code></code-example><p translation-result="on"><code>form</code> 标签所发出的 <code>submit</code> 事件是原生 DOM 事件，通过点击类型为 <code>submit</code> 的按钮可以触发本事件。这还让用户可以用回车键来提交填完的表单。</p><p translation-origin="off">The <code>submit</code> event is emitted by the <code>form</code> tag using the native DOM event. You trigger the event by clicking a button with <code>submit</code> type. This allows the user to press the <strong>Enter</strong> key to submit the completed form.</p><p translation-result="on">往表单的底部添加一个 <code>button</code>，用于触发表单提交。</p><p translation-origin="off">Use a <code>button</code> element to add a button to the bottom of the form to trigger the form submission.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.html" region="submit-button" header="src/app/profile-editor/profile-editor.component.html (submit button)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;button type="submit" [disabled]="!profileForm.valid"&gt;Submit&lt;/button&gt;</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.html (submit button)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.html (submit button)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"submit"</span><span class="pln"> [</span><span class="atn">disabled</span><span class="pln">]</span><span class="pun">=</span><span class="atv">"!profileForm.valid"</span><span class="tag">&gt;</span><span class="pln">Submit</span><span class="tag">&lt;/button&gt;</span></code>
    </pre></aio-code></code-example><div class="alert is-helpful"><p translation-result="on"><em>注意：</em>上面这个代码片段中的按钮还附加了一个 <code>disabled</code> 绑定，用于在 <code>profileForm</code> 无效时禁用该按钮。目前你还没有执行任何表单验证逻辑，因此该按钮始终是可用的。稍后的<a href="guide/reactive-forms#simple-form-validation">表单验证</a>一节会讲解简单的表单验证。</p><p translation-origin="off"><strong>Note:</strong> The button in the snippet above also has a <code>disabled</code> binding attached to it to disable the button when <code>profileForm</code> is invalid. You aren't performing any validation yet, so the button is always enabled. Simple form validation is covered in the <a href="guide/reactive-forms#simple-form-validation">Simple form validation</a> section.</p></div><h4 id="displaying-the-component-1" translation-result="on">显示组件<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#displaying-the-component-1"><i class="material-icons">link</i></a></h4><h4 translation-origin="off" id="displaying-the-component-1">Displaying the component<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#displaying-the-component-1"><i class="material-icons">link</i></a></h4><p translation-result="on">要显示包含此表单的 <code>ProfileEditor</code> 组件，请把它添加到组件模板中。</p><p translation-origin="off">To display the <code>ProfileEditor</code> component that contains the form, add it to a component template.</p><code-example path="reactive-forms/src/app/app.component.1.html" region="app-profile-editor" header="src/app/app.component.html (profile editor)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;app-profile-editor&gt;&lt;/app-profile-editor&gt;</div><header class="ng-star-inserted">src/app/app.component.html (profile editor)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app.component.html (profile editor)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;app-profile-editor&gt;&lt;/app-profile-editor&gt;</span></code>
    </pre></aio-code></code-example><p translation-result="on"><code>ProfileEditor</code> 让你能管理 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 中的 <code>firstName</code> 和 <code>lastName</code> 等 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 实例。</p><p translation-origin="off"><code>ProfileEditor</code> allows you to manage the form control instances for the <code>firstName</code> and <code>lastName</code> controls within the form group instance.</p><div class="lightbox"><img src="generated/images/guide/reactive-forms/profile-editor-1.png" alt="Profile Editor" width="351" height="184"></div><h2 id="creating-nested-form-groups" translation-result="on">嵌套的表单组<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#creating-nested-form-groups"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="creating-nested-form-groups">Creating nested form groups<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#creating-nested-form-groups"><i class="material-icons">link</i></a></h2><p translation-result="on">如果要构建复杂的表单，如果能在更小的分区中管理不同类别的信息就会更容易一些，而有些信息分组可能会自然的汇入另一个更大的组中。使用嵌套的 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 可以让你把大型表单组织成一些稍小的、易管理的分组。</p><p translation-origin="off">When building complex forms, managing the different areas of information is easier in smaller sections, and some groups of information naturally fall into the same group. Using a nested form group instance allows you to break large forms groups into smaller, more manageable ones.</p><h3 id="step-1-creating-a-nested-group" translation-result="on">步骤 1 - 创建嵌套的分组<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-1-creating-a-nested-group"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="step-1-creating-a-nested-group">Step 1: Creating a nested group<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-1-creating-a-nested-group"><i class="material-icons">link</i></a></h3><p translation-result="on">“地址”就是可以把信息进行分组的绝佳范例。<code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 可以同时接纳 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 和 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 作为子控件。这使得那些比较复杂的表单模型可以更易于维护、更有逻辑性。要想在 <code>profileForm</code> 中创建一个嵌套的分组，请添加一个内嵌的名叫 <code>address</code> 的元素指向这个 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 实例。</p><p translation-origin="off">An address is a good example of information that can be grouped together. Form groups can accept both form control and form group instances as children. This makes composing complex form models easier to maintain and logically group together. To create a nested group in <code>profileForm</code>, add a nested <code>address</code> element to the form group instance.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.1.ts" region="nested-formgroup" header="src/app/profile-editor/profile-editor.component.ts (nested form group)" ng-version="9.0.0-rc.11"><div style="display:none">import { <a href="api/core/Component" class="code-anchor">Component</a> } from '@angular/core'; import { <a href="api/forms/FormGroup" class="code-anchor">FormGroup</a>, <a href="api/forms/FormControl" class="code-anchor">FormControl</a> } from '@angular/forms'; @<a href="api/core/Component" class="code-anchor">Component</a>({ selector: 'app-profile-editor', <a href="api/core/Component#templateUrl" class="code-anchor">templateUrl</a>: './profile-editor.component.html', <a href="api/core/Component#styleUrls" class="code-anchor">styleUrls</a>: ['./profile-editor.component.css'] }) export class ProfileEditorComponent { profileForm = new <a href="api/forms/FormGroup" class="code-anchor">FormGroup</a>({ firstName: new <a href="api/forms/FormControl" class="code-anchor">FormControl</a>(''), lastName: new <a href="api/forms/FormControl" class="code-anchor">FormControl</a>(''), address: new <a href="api/forms/FormGroup" class="code-anchor">FormGroup</a>({ street: new <a href="api/forms/FormControl" class="code-anchor">FormControl</a>(''), city: new <a href="api/forms/FormControl" class="code-anchor">FormControl</a>(''), <a href="api/animations/state" class="code-anchor">state</a>: new <a href="api/forms/FormControl" class="code-anchor">FormControl</a>(''), zip: new <a href="api/forms/FormControl" class="code-anchor">FormControl</a>('') }) }); }</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.ts (nested form group)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.ts (nested form group)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/core/Component" class="code-anchor"><span class="typ">Component</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/core'</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/forms/FormGroup" class="code-anchor"><span class="typ">FormGroup</span></a><span class="pun">,</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/forms'</span><span class="pun">;</span><span class="pln">

</span><span class="lit">@</span><a href="api/core/Component" class="code-anchor"><span class="lit">Component</span></a><span class="pun">({</span><span class="pln">
  selector</span><span class="pun">:</span><span class="pln"> </span><span class="str">'app-profile-editor'</span><span class="pun">,</span><span class="pln">
  </span><a href="api/core/Component#templateUrl" class="code-anchor"><span class="pln">templateUrl</span></a><span class="pun">:</span><span class="pln"> </span><span class="str">'./profile-editor.component.html'</span><span class="pun">,</span><span class="pln">
  </span><a href="api/core/Component#styleUrls" class="code-anchor"><span class="pln">styleUrls</span></a><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">'./profile-editor.component.css'</span><span class="pun">]</span><span class="pln">
</span><span class="pun">})</span><span class="pln">
</span><span class="kwd">export</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">ProfileEditorComponent</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  profileForm </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormGroup" class="code-anchor"><span class="typ">FormGroup</span></a><span class="pun">({</span><span class="pln">
    firstName</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pun">(</span><span class="str">''</span><span class="pun">),</span><span class="pln">
    lastName</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pun">(</span><span class="str">''</span><span class="pun">),</span><span class="pln">
    address</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormGroup" class="code-anchor"><span class="typ">FormGroup</span></a><span class="pun">({</span><span class="pln">
      street</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pun">(</span><span class="str">''</span><span class="pun">),</span><span class="pln">
      city</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pun">(</span><span class="str">''</span><span class="pun">),</span><span class="pln">
      </span><a href="api/animations/state" class="code-anchor"><span class="pln">state</span></a><span class="pun">:</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pun">(</span><span class="str">''</span><span class="pun">),</span><span class="pln">
      zip</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pun">(</span><span class="str">''</span><span class="pun">)</span><span class="pln">
    </span><span class="pun">})</span><span class="pln">
  </span><span class="pun">});</span><span class="pln">
</span><span class="pun">}</span></code>
    </pre></aio-code></code-example><p translation-result="on">在这个例子中，<code>address group</code> 把现有的 <code>firstName</code>、<code>lastName</code> 控件和新的 <code>street</code>、<code>city</code>、<code><a href="api/animations/state" class="code-anchor">state</a></code> 和 <code>zip</code> 控件组合在一起。虽然 <code>address</code> 这个 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 是 <code>profileForm</code> 这个整体 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 的一个子控件，但是仍然适用同样的值和状态的变更规则。来自内嵌控件组的状态和值的变更将会冒泡到它的父控件组，以维护整体模型的一致性。</p><p translation-origin="off">In this example, <code>address group</code> combines the current <code>firstName</code> and <code>lastName</code> controls with the new <code>street</code>, <code>city</code>, <code><a href="api/animations/state" class="code-anchor">state</a></code>, and <code>zip</code> controls. Even though the <code>address</code> element in the form group is a child of the overall <code>profileForm</code> element in the form group, the same rules apply with value and status changes. Changes in status and value from the nested form group propagate to the parent form group, maintaining consistency with the overall model.</p><h3 id="step-2-grouping-the-nested-form-in-the-template" translation-result="on">步骤 2 - 在模板中分组内嵌的表单<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-2-grouping-the-nested-form-in-the-template"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="step-2-grouping-the-nested-form-in-the-template">Step 2: Grouping the nested form in the template<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-2-grouping-the-nested-form-in-the-template"><i class="material-icons">link</i></a></h3><p translation-result="on">在修改了组件类中的模型之后，还要修改模板，来把这个 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 实例对接到它的输入元素。</p><p translation-origin="off">After you update the model in the component class, update the template to connect the form group instance and its input elements.</p><p translation-result="on">把包含 <code>street</code>、<code>city</code>、<code><a href="api/animations/state" class="code-anchor">state</a></code> 和 <code>zip</code> 字段的 <code>address</code> 表单组添加到 <code>ProfileEditor</code> 模板中。</p><p translation-origin="off">Add the <code>address</code> form group containing the <code>street</code>, <code>city</code>, <code><a href="api/animations/state" class="code-anchor">state</a></code>, and <code>zip</code> fields to the <code>ProfileEditor</code> template.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.1.html" region="formgroupname" header="src/app/profile-editor/profile-editor.component.html (template nested form group)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;div <a href="api/forms/FormGroupName" class="code-anchor">formGroupName</a>="address"&gt; &lt;h3&gt;Address&lt;/h3&gt; &lt;label&gt; Street: &lt;input type="text" <a href="api/forms/FormControlName" class="code-anchor">formControlName</a>="street"&gt; &lt;/label&gt; &lt;label&gt; City: &lt;input type="text" <a href="api/forms/FormControlName" class="code-anchor">formControlName</a>="city"&gt; &lt;/label&gt; &lt;label&gt; <a href="api/animations/AnimationMetadataType#State" class="code-anchor">State</a>: &lt;input type="text" <a href="api/forms/FormControlName" class="code-anchor">formControlName</a>="<a href="api/animations/state" class="code-anchor">state</a>"&gt; &lt;/label&gt; &lt;label&gt; Zip Code: &lt;input type="text" <a href="api/forms/FormControlName" class="code-anchor">formControlName</a>="zip"&gt; &lt;/label&gt; &lt;/div&gt;</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.html (template nested form group)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.html (template nested form group)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;div</span><span class="pln"> </span><a href="api/forms/FormGroupName" class="code-anchor"><span class="atn">formGroupName</span></a><span class="pun">=</span><span class="atv">"address"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;h3&gt;</span><span class="pln">Address</span><span class="tag">&lt;/h3&gt;</span><span class="pln">

  </span><span class="tag">&lt;label&gt;</span><span class="pln">
    Street:
    </span><span class="tag">&lt;input</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text"</span><span class="pln"> </span><a href="api/forms/FormControlName" class="code-anchor"><span class="atn">formControlName</span></a><span class="pun">=</span><span class="atv">"street"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;/label&gt;</span><span class="pln">

  </span><span class="tag">&lt;label&gt;</span><span class="pln">
    City:
    </span><span class="tag">&lt;input</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text"</span><span class="pln"> </span><a href="api/forms/FormControlName" class="code-anchor"><span class="atn">formControlName</span></a><span class="pun">=</span><span class="atv">"city"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;/label&gt;</span><span class="pln">
  
  </span><span class="tag">&lt;label&gt;</span><span class="pln">
    </span><a href="api/animations/AnimationMetadataType#State" class="code-anchor"><span class="pln">State</span></a><span class="pln">:
    </span><span class="tag">&lt;input</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text"</span><span class="pln"> </span><a href="api/forms/FormControlName" class="code-anchor"><span class="atn">formControlName</span></a><span class="pun">=</span><span class="atv">"</span><a href="api/animations/state" class="code-anchor"><span class="atv">state</span></a><span class="atv">"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;/label&gt;</span><span class="pln">

  </span><span class="tag">&lt;label&gt;</span><span class="pln">
    Zip Code:
    </span><span class="tag">&lt;input</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text"</span><span class="pln"> </span><a href="api/forms/FormControlName" class="code-anchor"><span class="atn">formControlName</span></a><span class="pun">=</span><span class="atv">"zip"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;/label&gt;</span><span class="pln">
</span><span class="tag">&lt;/div&gt;</span></code>
    </pre></aio-code></code-example><p translation-result="on"><code>ProfileEditor</code> 表单显示为一个组，但是将来这个模型会被进一步细分，以表示逻辑分组区域。</p><p translation-origin="off">The <code>ProfileEditor</code> form is displayed as one group, but the model is broken down further to represent the logical grouping areas.</p><div class="lightbox"><img src="generated/images/guide/reactive-forms/profile-editor-2.png" alt="Profile Editor Update" width="350" height="435"></div><div class="alert is-helpful"><p translation-result="on"><em>注意</em>：这里使用了 <code>value</code> 属性和 <code><a href="api/common/JsonPipe" class="code-anchor">JsonPipe</a></code> 管道在组件模板中显示了这个 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 的值。</p><p translation-origin="off"><strong>Note:</strong> Display the value for the form group instance in the component template using the <code>value</code> property and <code><a href="api/common/JsonPipe" class="code-anchor">JsonPipe</a></code>.</p></div><h2 id="partial-model-updates" translation-result="on">部分模型更新<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#partial-model-updates"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="partial-model-updates">Partial model updates<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#partial-model-updates"><i class="material-icons">link</i></a></h2><p translation-result="on">当修改包含多个 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 实例的值时，你可能只希望更新模型中的一部分，而不是完全替换掉。这一节会讲解该如何更新 <code><a href="api/forms/AbstractControl" class="code-anchor">AbstractControl</a></code> 模型中的一部分。</p><p translation-origin="off">When updating the value for a form group instance that contains multiple controls, you may only want to update parts of the model. This section covers how to update specific parts of a form control data model.</p><h3 id="patching-the-model-value" translation-result="on">修补（Patching）模型值<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#patching-the-model-value"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="patching-the-model-value">Patching the model value<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#patching-the-model-value"><i class="material-icons">link</i></a></h3><p translation-result="on">有两种更新模型值的方式：</p><p translation-origin="off">There are two ways to update the model value:</p><ul><li><p translation-result="on">使用 <code>setValue()</code> 方法来为单个控件设置新值。 <code>setValue()</code> 方法会严格遵循表单组的结构，并整体性替换控件的值。</p><p translation-origin="off">Use the <code>setValue()</code> method to set a new value for an individual control. The <code>setValue()</code> method strictly adheres to the structure of the form group and replaces the entire value for the control.</p></li><li><p translation-result="on">使用 <code>patchValue()</code> 方法可以用对象中所定义的任何属性为表单模型进行替换。</p><p translation-origin="off">Use the <code>patchValue()</code> method to replace any properties defined in the object that have changed in the form model.</p></li></ul><p translation-result="on"><code>setValue()</code> 方法的严格检查可以帮助你捕获复杂表单嵌套中的错误，而 <code>patchValue()</code> 在遇到那些错误时可能会默默的失败。</p><p translation-origin="off">The strict checks of the <code>setValue()</code> method help catch nesting errors in complex forms, while <code>patchValue()</code> fails silently on those errors.</p><p translation-result="on">在 <code>ProfileEditorComponent</code> 中，使用 <code>updateProfile</code> 方法传入下列数据可以更新用户的名字与街道住址。</p><p translation-origin="off">In <code>ProfileEditorComponent</code>, use the <code>updateProfile</code> method with the example below to update the first name and street address for the user.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.1.ts" region="patch-value" header="src/app/profile-editor/profile-editor.component.ts (patch value)" ng-version="9.0.0-rc.11"><div style="display:none">updateProfile() { this.profileForm.patchValue({ firstName: 'Nancy', address: { street: '123 Drew Street' } }); }</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.ts (patch value)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.ts (patch value)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">updateProfile</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">profileForm</span><span class="pun">.</span><span class="pln">patchValue</span><span class="pun">({</span><span class="pln">
    firstName</span><span class="pun">:</span><span class="pln"> </span><span class="str">'Nancy'</span><span class="pun">,</span><span class="pln">
    address</span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
      street</span><span class="pun">:</span><span class="pln"> </span><span class="str">'123 Drew Street'</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
  </span><span class="pun">});</span><span class="pln">
</span><span class="pun">}</span></code>
    </pre></aio-code></code-example><p translation-result="on">通过往模板中添加一个按钮来模拟一次更新操作，以修改用户档案。</p><p translation-origin="off">Simulate an update by adding a button to the template to update the user profile on demand.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.1.html" region="patch-value" header="src/app/profile-editor/profile-editor.component.html (update value)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;p&gt; &lt;button (click)="updateProfile()"&gt;<a href="" class="code-anchor">Update</a> Profile&lt;/button&gt; &lt;/p&gt;</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.html (update value)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.html (update value)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;p&gt;</span><span class="pln">
  </span><span class="tag">&lt;button</span><span class="pln"> (</span><span class="atn">click</span><span class="pln">)</span><span class="pun">=</span><span class="atv">"updateProfile()"</span><span class="tag">&gt;</span><a href="" class="code-anchor"><span class="pln">Update</span></a><span class="pln"> Profile</span><span class="tag">&lt;/button&gt;</span><span class="pln">
</span><span class="tag">&lt;/p&gt;</span></code>
    </pre></aio-code></code-example><p translation-result="on">当点击按钮时，<code>profileForm</code> 模型中只有 <code>firstName</code> 和 <code>street</code> 被修改了。注意，<code>street</code> 是在 <code>address</code> 属性的对象中被修改的。这种结构是必须的，因为 <code>patchValue()</code> 方法要针对模型的结构进行更新。<code>patchValue()</code> 只会更新表单模型中所定义的那些属性。</p><p translation-origin="off">When a user clicks the button, the <code>profileForm</code> model is updated with new values for <code>firstName</code> and <code>street</code>. Notice that <code>street</code> is provided in an object inside the <code>address</code> property. This is necessary because the <code>patchValue()</code> method applies the update against the model structure. <code>PatchValue()</code> only updates properties that the form model defines.</p><h2 id="generating-form-controls-with-formbuilder" translation-result="on">使用 <code><a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a></code> 来生成表单控件<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#generating-form-controls-with-formbuilder"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="generating-form-controls-with-formbuilder">Generating form controls with FormBuilder<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#generating-form-controls-with-formbuilder"><i class="material-icons">link</i></a></h2><p translation-result="on">当需要与多个表单打交道时，手动创建多个表单控件实例会非常繁琐。<code><a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a></code> 服务提供了一些便捷方法来生成表单控件。<code><a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a></code> 在幕后也使用同样的方式来创建和返回这些实例，只是用起来更简单。</p><p translation-origin="off">Creating form control instances manually can become repetitive when dealing with multiple forms. The <code><a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a></code> service provides convenient methods for generating controls.</p><p translation-result="on">下面的小节中会重构 <code>ProfileEditor</code> 组件，用 <code><a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a></code> 来代替手工创建这些 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 和 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 实例。</p><p translation-origin="off">The following section refactors the <code>ProfileEditor</code> component to use the form builder service to create form control and form group instances.</p><h3 id="step-1-importing-the-formbuilder-class" translation-result="on">步骤 1 - 导入 <code><a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a></code> 类<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-1-importing-the-formbuilder-class"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="step-1-importing-the-formbuilder-class">Step 1: Importing the FormBuilder class<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-1-importing-the-formbuilder-class"><i class="material-icons">link</i></a></h3><p translation-result="on">从 <code>@angular/forms</code> 包中导入 <code><a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a></code> 类。</p><p translation-origin="off">Import the <code><a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a></code> class from the <code>@angular/forms</code> package.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.2.ts" region="form-builder-imports" header="src/app/profile-editor/profile-editor.component.ts (import)" ng-version="9.0.0-rc.11"><div style="display:none">import { <a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a> } from '@angular/forms';</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.ts (import)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.ts (import)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/forms/FormBuilder" class="code-anchor"><span class="typ">FormBuilder</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/forms'</span><span class="pun">;</span></code>
    </pre></aio-code></code-example><h3 id="step-2-injecting-the-formbuilder-service" translation-result="on">步骤 2 - 注入 <code><a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a></code> 服务<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-2-injecting-the-formbuilder-service"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="step-2-injecting-the-formbuilder-service">Step 2: Injecting the FormBuilder service<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-2-injecting-the-formbuilder-service"><i class="material-icons">link</i></a></h3><p translation-result="on"><code><a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a></code> 是一个可注入的服务提供商，它是由 <code>ReactiveFormModule</code> 提供的。只要把它添加到组件的构造函数中就可以注入这个依赖。</p><p translation-origin="off">The <code><a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a></code> service is an injectable provider that is provided with the reactive forms module. Inject this dependency by adding it to the component constructor.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.2.ts" region="inject-form-builder" header="src/app/profile-editor/profile-editor.component.ts (constructor)" ng-version="9.0.0-rc.11"><div style="display:none">constructor(private fb: <a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a>) { }</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.ts (constructor)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.ts (constructor)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">constructor</span><span class="pun">(</span><span class="kwd">private</span><span class="pln"> fb</span><span class="pun">:</span><span class="pln"> </span><a href="api/forms/FormBuilder" class="code-anchor"><span class="typ">FormBuilder</span></a><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="pun">}</span></code>
    </pre></aio-code></code-example><h3 id="step-3-generating-form-controls" translation-result="on">步骤 3 - 生成表单控件<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-3-generating-form-controls"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="step-3-generating-form-controls">Step 3: Generating form controls<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-3-generating-form-controls"><i class="material-icons">link</i></a></h3><p translation-result="on"><code><a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a></code> 服务有三个方法：<code><a href="api/forms/FormBuilder#control" class="code-anchor">control()</a></code>、<code><a href="api/forms/FormBuilder#group" class="code-anchor">group()</a></code> 和 <code><a href="api/forms/FormBuilder#array" class="code-anchor">array()</a></code>。这些方法都是工厂方法，用于在组件类中分别生成 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code>、<code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 和 <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code>。</p><p translation-origin="off">The <code><a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a></code> service has three methods: <code><a href="api/forms/FormBuilder#control" class="code-anchor">control()</a></code>, <code><a href="api/forms/FormBuilder#group" class="code-anchor">group()</a></code>, and <code><a href="api/forms/FormBuilder#array" class="code-anchor">array()</a></code>. These are factory methods for generating instances in your component classes including form controls, form groups, and form arrays.</p><p translation-result="on">用 <code><a href="api/animations/group" class="code-anchor">group</a></code> 方法来创建 <code>profileForm</code> 控件。</p><p translation-origin="off">Use the <code><a href="api/animations/group" class="code-anchor">group</a></code> method to create the <code>profileForm</code> controls.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.2.ts" region="form-builder" header="src/app/profile-editor/profile-editor.component.ts (form builder)" ng-version="9.0.0-rc.11"><div style="display:none">import { <a href="api/core/Component" class="code-anchor">Component</a> } from '@angular/core'; import { <a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a> } from '@angular/forms'; @<a href="api/core/Component" class="code-anchor">Component</a>({ selector: 'app-profile-editor', <a href="api/core/Component#templateUrl" class="code-anchor">templateUrl</a>: './profile-editor.component.html', <a href="api/core/Component#styleUrls" class="code-anchor">styleUrls</a>: ['./profile-editor.component.css'] }) export class ProfileEditorComponent { profileForm = this.fb.group({ firstName: [''], lastName: [''], address: this.fb.group({ street: [''], city: [''], <a href="api/animations/state" class="code-anchor">state</a>: [''], zip: [''] }), }); constructor(private fb: <a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a>) { } }</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.ts (form builder)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.ts (form builder)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/core/Component" class="code-anchor"><span class="typ">Component</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/core'</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/forms/FormBuilder" class="code-anchor"><span class="typ">FormBuilder</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/forms'</span><span class="pun">;</span><span class="pln">

</span><span class="lit">@</span><a href="api/core/Component" class="code-anchor"><span class="lit">Component</span></a><span class="pun">({</span><span class="pln">
  selector</span><span class="pun">:</span><span class="pln"> </span><span class="str">'app-profile-editor'</span><span class="pun">,</span><span class="pln">
  </span><a href="api/core/Component#templateUrl" class="code-anchor"><span class="pln">templateUrl</span></a><span class="pun">:</span><span class="pln"> </span><span class="str">'./profile-editor.component.html'</span><span class="pun">,</span><span class="pln">
  </span><a href="api/core/Component#styleUrls" class="code-anchor"><span class="pln">styleUrls</span></a><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">'./profile-editor.component.css'</span><span class="pun">]</span><span class="pln">
</span><span class="pun">})</span><span class="pln">
</span><span class="kwd">export</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">ProfileEditorComponent</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  profileForm </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">fb</span><span class="pun">.</span><span class="kwd">group</span><span class="pun">({</span><span class="pln">
    firstName</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">],</span><span class="pln">
    lastName</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">],</span><span class="pln">
    address</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">fb</span><span class="pun">.</span><span class="kwd">group</span><span class="pun">({</span><span class="pln">
      street</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">],</span><span class="pln">
      city</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">],</span><span class="pln">
      </span><a href="api/animations/state" class="code-anchor"><span class="pln">state</span></a><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">],</span><span class="pln">
      zip</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">]</span><span class="pln">
    </span><span class="pun">}),</span><span class="pln">
  </span><span class="pun">});</span><span class="pln">

  </span><span class="kwd">constructor</span><span class="pun">(</span><span class="kwd">private</span><span class="pln"> fb</span><span class="pun">:</span><span class="pln"> </span><a href="api/forms/FormBuilder" class="code-anchor"><span class="typ">FormBuilder</span></a><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span></code>
    </pre></aio-code></code-example><p translation-result="on">在上面的例子中，你可以使用 <code><a href="api/forms/FormBuilder#group" class="code-anchor">group()</a></code> 方法，用和前面一样的名字来定义这些属性。这里，每个控件名对应的值都是一个数组，这个数组中的第一项是其初始值。</p><p translation-origin="off">In the example above, you use the <code><a href="api/forms/FormBuilder#group" class="code-anchor">group()</a></code> method with the same object to define the properties in the model. The value for each control name is an array containing the initial value as the first item in the array.</p><div class="alert is-helpful"><p translation-result="on"><em>注意</em>：你可以只使用初始值来定义控件，但是如果你的控件还需要同步或异步验证器，那就在这个数组中的第二项和第三项提供同步和异步验证器。</p><p translation-origin="off"><strong>Note:</strong> You can define the control with just the initial value, but if your controls need sync or async validation, add sync and async validators as the second and third items in the array.</p></div><p translation-result="on">比较一下用表单构建器和手动创建实例这两种方式。</p><p translation-origin="off">Compare using the form builder to creating the instances manually.</p><code-tabs ng-version="9.0.0-rc.11"><div style="display:none"><code-pane path="reactive-forms/src/app/profile-editor/profile-editor.component.1.ts" region="formgroup-compare" header="src/app/profile-editor/profile-editor.component.ts (instances)">profileForm = new <a href="api/forms/FormGroup" class="code-anchor">FormGroup</a>({ firstName: new <a href="api/forms/FormControl" class="code-anchor">FormControl</a>(''), lastName: new <a href="api/forms/FormControl" class="code-anchor">FormControl</a>(''), address: new <a href="api/forms/FormGroup" class="code-anchor">FormGroup</a>({ street: new <a href="api/forms/FormControl" class="code-anchor">FormControl</a>(''), city: new <a href="api/forms/FormControl" class="code-anchor">FormControl</a>(''), <a href="api/animations/state" class="code-anchor">state</a>: new <a href="api/forms/FormControl" class="code-anchor">FormControl</a>(''), zip: new <a href="api/forms/FormControl" class="code-anchor">FormControl</a>('') }) });</code-pane><code-pane path="reactive-forms/src/app/profile-editor/profile-editor.component.2.ts" region="formgroup-compare" header="src/app/profile-editor/profile-editor.component.ts (form builder)">profileForm = this.fb.group({ firstName: [''], lastName: [''], address: this.fb.group({ street: [''], city: [''], <a href="api/animations/state" class="code-anchor">state</a>: [''], zip: [''] }), });</code-pane></div><mat-card class="mat-card"><mat-tab-group class="mat-tab-group code-tab-group mat-primary"><mat-tab-header class="mat-tab-header mat-tab-header-pagination-controls-enabled"><div aria-hidden="true" mat-ripple="" class="mat-ripple mat-tab-header-pagination mat-tab-header-pagination-before mat-elevation-z4 mat-tab-header-pagination-disabled"><div class="mat-tab-header-pagination-chevron"></div></div><div class="mat-tab-label-container"><div role="tablist" class="mat-tab-list" style="transform:translateX(0)"><div class="mat-tab-labels"><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label mat-tab-label-active ng-star-inserted" id="mat-tab-label-0-0" tabindex="0" aria-posinset="1" aria-setsize="2" aria-controls="mat-tab-content-0-0" aria-selected="true" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/profile-editor/profile-editor.component.ts (instances)</span></div></div><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label ng-star-inserted" id="mat-tab-label-0-1" tabindex="-1" aria-posinset="2" aria-setsize="2" aria-controls="mat-tab-content-0-1" aria-selected="false" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/profile-editor/profile-editor.component.ts (form builder)</span></div></div></div><mat-ink-bar class="mat-ink-bar" style="visibility:visible;left:0;width:417px"></mat-ink-bar></div></div><div aria-hidden="true" mat-ripple="" class="mat-ripple mat-tab-header-pagination mat-tab-header-pagination-after mat-elevation-z4"><div class="mat-tab-header-pagination-chevron"></div></div></mat-tab-header><div class="mat-tab-body-wrapper"><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-2 mat-tab-body-active ng-star-inserted" id="mat-tab-content-0-0" aria-labelledby="mat-tab-label-0-0"><div class="mat-tab-body-content ng-tns-c50-2 ng-trigger ng-trigger-translateTab" style="transform:none"><aio-code class="ng-star-inserted" style=""><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.ts (instances)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">profileForm </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormGroup" class="code-anchor"><span class="typ">FormGroup</span></a><span class="pun">({</span><span class="pln">
  firstName</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pun">(</span><span class="str">''</span><span class="pun">),</span><span class="pln">
  lastName</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pun">(</span><span class="str">''</span><span class="pun">),</span><span class="pln">
  address</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormGroup" class="code-anchor"><span class="typ">FormGroup</span></a><span class="pun">({</span><span class="pln">
    street</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pun">(</span><span class="str">''</span><span class="pun">),</span><span class="pln">
    city</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pun">(</span><span class="str">''</span><span class="pun">),</span><span class="pln">
    </span><a href="api/animations/state" class="code-anchor"><span class="pln">state</span></a><span class="pun">:</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pun">(</span><span class="str">''</span><span class="pun">),</span><span class="pln">
    zip</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><a href="api/forms/FormControl" class="code-anchor"><span class="typ">FormControl</span></a><span class="pun">(</span><span class="str">''</span><span class="pun">)</span><span class="pln">
  </span><span class="pun">})</span><span class="pln">
</span><span class="pun">});</span></code>
    </pre></aio-code></div></mat-tab-body><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-3 ng-star-inserted" id="mat-tab-content-0-1" aria-labelledby="mat-tab-label-0-1"><div class="mat-tab-body-content ng-tns-c50-3 ng-trigger ng-trigger-translateTab" style="transform:translate3d(100%,0,0);min-height:1px"></div></mat-tab-body></div></mat-tab-group></mat-card></code-tabs><h2 id="simple-form-validation" translation-result="on">简单表单验证<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#simple-form-validation"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="simple-form-validation">Simple form validation<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#simple-form-validation"><i class="material-icons">link</i></a></h2><p translation-result="on"><em>表单验证</em>用于验证用户的输入，以确保其完整和正确。本节讲解了如何把单个验证器添加到表单控件中，以及如何显示表单的整体状态。表单验证的更多知识在<a href="guide/form-validation">表单验证</a>一章中有详细的讲解。</p><p translation-origin="off"><em>Form validation</em> is used to validate user input to ensure it's complete and correct. This section covers adding a single validator to a form control and displaying the overall form status. Form validation is covered more extensively in the <a href="guide/form-validation">Form Validation</a> guide.</p><h3 id="step-1-importing-a-validator-function" translation-result="on">步骤 1 - 导入验证器函数<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-1-importing-a-validator-function"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="step-1-importing-a-validator-function">Step 1: Importing a validator function<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-1-importing-a-validator-function"><i class="material-icons">link</i></a></h3><p translation-result="on">响应式表单包含了一组开箱即用的常用验证器函数。这些函数接收一个控件，用以验证并根据验证结果返回一个错误对象或空值。</p><p translation-origin="off">Reactive forms include a set of validator functions for common use cases. These functions receive a control to validate against and return an error object or a null value based on the validation check.</p><p translation-result="on">从 <code>@angular/forms</code> 包中导入 <code><a href="api/forms/Validators" class="code-anchor">Validators</a></code> 类。</p><p translation-origin="off">Import the <code><a href="api/forms/Validators" class="code-anchor">Validators</a></code> class from the <code>@angular/forms</code> package.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.ts" region="validator-imports" header="src/app/profile-editor/profile-editor.component.ts (import)" ng-version="9.0.0-rc.11"><div style="display:none">import { <a href="api/forms/Validators" class="code-anchor">Validators</a> } from '@angular/forms';</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.ts (import)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.ts (import)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/forms/Validators" class="code-anchor"><span class="typ">Validators</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/forms'</span><span class="pun">;</span></code>
    </pre></aio-code></code-example><h3 id="step-2-making-a-field-required" translation-result="on">步骤 2 - 把字段设为必填（required）<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-2-making-a-field-required"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="step-2-making-a-field-required">Step 2: Making a field required<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-2-making-a-field-required"><i class="material-icons">link</i></a></h3><p translation-result="on">最常见的校验项是把一个字段设为必填项。本节描述如何为 <code>firstName</code> 控件添加“必填项”验证器。</p><p translation-origin="off">The most common validation is making a field required. This section describes how to add a required validation to the <code>firstName</code> control.</p><p translation-result="on">在 <code>ProfileEditor</code> 组件中，把静态方法 <code>Validators.required</code> 设置为 <code>firstName</code> 控件值数组中的第二项。</p><p translation-origin="off">In the <code>ProfileEditor</code> component, add the <code>Validators.required</code> static method as the second item in the array for the <code>firstName</code> control.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.ts" region="required-validator" header="src/app/profile-editor/profile-editor.component.ts (required validator)" ng-version="9.0.0-rc.11"><div style="display:none">profileForm = this.fb.group({ firstName: ['', Validators.required], lastName: [''], address: this.fb.group({ street: [''], city: [''], <a href="api/animations/state" class="code-anchor">state</a>: [''], zip: [''] }), });</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.ts (required validator)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.ts (required validator)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">profileForm </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">fb</span><span class="pun">.</span><span class="kwd">group</span><span class="pun">({</span><span class="pln">
  firstName</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">,</span><span class="pln"> </span><span class="typ">Validators</span><span class="pun">.</span><span class="pln">required</span><span class="pun">],</span><span class="pln">
  lastName</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">],</span><span class="pln">
  address</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">fb</span><span class="pun">.</span><span class="kwd">group</span><span class="pun">({</span><span class="pln">
    street</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">],</span><span class="pln">
    city</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">],</span><span class="pln">
    </span><a href="api/animations/state" class="code-anchor"><span class="pln">state</span></a><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">],</span><span class="pln">
    zip</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">]</span><span class="pln">
  </span><span class="pun">}),</span><span class="pln">
</span><span class="pun">});</span></code>
    </pre></aio-code></code-example><p translation-result="on">HTML5 有一组内置的属性，用来进行原生验证，包括 <code>required</code>、<code><a href="api/forms/MinLengthValidator" class="code-anchor">minlength</a></code>、<code><a href="api/forms/MaxLengthValidator" class="code-anchor">maxlength</a></code> 等。虽然是<em>可选的</em>，不过你也可以在表单的输入元素上把它们添加为附加属性来使用它们。这里我们把 <code>required</code> 属性添加到 <code>firstName</code> 输入元素上。</p><p translation-origin="off">HTML5 has a set of built-in attributes that you can use for native validation, including <code>required</code>, <code><a href="api/forms/MinLengthValidator" class="code-anchor">minlength</a></code>, and <code><a href="api/forms/MaxLengthValidator" class="code-anchor">maxlength</a></code>. You can take advantage of these optional attributes on your form input elements. Add the <code>required</code> attribute to the <code>firstName</code> input element.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.html" region="required-attribute" header="src/app/profile-editor/profile-editor.component.html (required attribute)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;input type="text" <a href="api/forms/FormControlName" class="code-anchor">formControlName</a>="firstName" required&gt;</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.html (required attribute)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.html (required attribute)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;input</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text"</span><span class="pln"> </span><a href="api/forms/FormControlName" class="code-anchor"><span class="atn">formControlName</span></a><span class="pun">=</span><span class="atv">"firstName"</span><span class="pln"> </span><span class="atn">required</span><span class="tag">&gt;</span></code>
    </pre></aio-code></code-example><div class="alert is-important"><p translation-result="on"><em>注意：</em>这些 HTML5 验证器属性可以和 Angular 响应式表单提供的内置验证器<em>组合使用</em>。组合使用这两种验证器实践，可以防止在模板检查完之后表达式再次被修改导致的错误。</p><p translation-origin="off"><strong>Caution:</strong> Use these HTML5 validation attributes <em>in combination with</em> the built-in validators provided by Angular's reactive forms. Using these in combination prevents errors when the expression is changed after the template has been checked.</p></div><h3 id="displaying-form-status" translation-result="on">显示表单状态<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#displaying-form-status"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="displaying-form-status">Displaying form status<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#displaying-form-status"><i class="material-icons">link</i></a></h3><p translation-result="on">当你往表单控件上添加了一个必填字段时，它的初始值是无效的（invalid）。这种无效状态会传播到其父 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 元素中，也让这个 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 的状态变为无效的。你可以通过该 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 实例的 <code>status</code> 属性来访问其当前状态。</p><p translation-origin="off">When you add a required field to the form control, its initial status is invalid. This invalid status propagates to the parent form group element, making its status invalid. Access the current status of the form group instance through its <code>status</code> property.</p><p translation-result="on">使用插值显示 <code>profileForm</code> 的当前状态。</p><p translation-origin="off">Display the current status of <code>profileForm</code> using interpolation.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.html" region="display-status" header="src/app/profile-editor/profile-editor.component.html (display status)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;p&gt; <a href="api/forms/Form" class="code-anchor">Form</a> Status: {{ profileForm.status }} &lt;/p&gt;</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.html (display status)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.html (display status)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;p&gt;</span><span class="pln">
  </span><a href="api/forms/Form" class="code-anchor"><span class="pln">Form</span></a><span class="pln"> Status: {{ profileForm.status }}
</span><span class="tag">&lt;/p&gt;</span></code>
    </pre></aio-code></code-example><div class="lightbox"><img src="generated/images/guide/reactive-forms/profile-editor-3.png" alt="Profile Editor Validation" width="391" height="582"></div><p translation-result="on">提交按钮被禁用了，因为 <code>firstName</code> 控件的必填项规则导致了 <code>profileForm</code> 也是无效的。在你填写了 <code>firstName</code> 输入框之后，该表单就变成了有效的，并且提交按钮也启用了。</p><p translation-origin="off">The <strong>Submit</strong> button is disabled because <code>profileForm</code> is invalid due to the required <code>firstName</code> form control. After you fill out the <code>firstName</code> input, the form becomes valid and the <strong>Submit</strong> button is enabled.</p><p translation-result="on">要了解表单验证的更多知识，参见<a href="guide/form-validation">表单验证</a>一章。</p><p translation-origin="off">For more on form validation, visit the <a href="guide/form-validation">Form Validation</a> guide.</p><h2 id="dynamic-controls-using-form-arrays" translation-result="on">使用表单数组管理动态控件<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#dynamic-controls-using-form-arrays"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="dynamic-controls-using-form-arrays">Dynamic controls using form arrays<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#dynamic-controls-using-form-arrays"><i class="material-icons">link</i></a></h2><p translation-result="on"><code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> 是 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 之外的另一个选择，用于管理任意数量的匿名控件。像 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 实例一样，你也可以往 <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> 中动态插入和移除控件，并且 <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> 实例的值和验证状态也是根据它的子控件计算得来的。 不过，你不需要为每个控件定义一个名字作为 key，因此，如果你事先不知道子控件的数量，这就是一个很好的选择。下面的例子展示了如何在 <code>ProfileEditor</code> 中管理一组<em>绰号</em>（aliases）。</p><p translation-origin="off"><code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> is an alternative to <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> for managing any number of unnamed controls. As with form group instances, you can dynamically insert and remove controls from form array instances, and the form array instance value and validation status is calculated from its child controls. However, you don't need to define a key for each control by name, so this is a great option if you don't know the number of child values in advance. The following example shows you how to manage an array of <em>aliases</em> in <code>ProfileEditor</code>.</p><h3 id="step-1-importing-the-formarray-class" translation-result="on">步骤 1 - 导入 <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code><a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-1-importing-the-formarray-class"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="step-1-importing-the-formarray-class">Step 1: Importing the FormArray class<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-1-importing-the-formarray-class"><i class="material-icons">link</i></a></h3><p translation-result="on">从 <code>@angular/form</code> 中导入 <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code>，以使用它的类型信息。<code><a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a></code> 服务用于创建 <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> 实例。</p><p translation-origin="off">Import the <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> class from <code>@angular/forms</code> to use for type information. The <code><a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a></code> service is ready to create a <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> instance.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.2.ts" region="form-array-imports" header="src/app/profile-editor/profile-editor.component.ts (import)" ng-version="9.0.0-rc.11"><div style="display:none">import { <a href="api/forms/FormArray" class="code-anchor">FormArray</a> } from '@angular/forms';</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.ts (import)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.ts (import)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/forms/FormArray" class="code-anchor"><span class="typ">FormArray</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/forms'</span><span class="pun">;</span></code>
    </pre></aio-code></code-example><h3 id="step-2-defining-a-formarray-control" translation-result="on">步骤 2 - 定义 <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code><a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-2-defining-a-formarray-control"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="step-2-defining-a-formarray-control">Step 2: Defining a FormArray control<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-2-defining-a-formarray-control"><i class="material-icons">link</i></a></h3><p translation-result="on">你可以通过把一组（从零项到多项）控件定义在一个数组中来初始化一个 <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code>。为 <code>profileForm</code> 添加一个 <code>aliases</code> 属性，把它定义为 <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> 类型。</p><p translation-origin="off">You can initialize a form array with any number of controls, from zero to many, by defining them in an array. Add an <code>aliases</code> property to the form group instance for <code>profileForm</code> to define the form array.</p><p translation-result="on">使用 <code><a href="api/forms/FormBuilder#array" class="code-anchor">FormBuilder.array()</a></code> 方法来定义该数组，并用 <code><a href="api/forms/FormBuilder#control" class="code-anchor">FormBuilder.control()</a></code> 方法来往该数组中添加一个初始控件。</p><p translation-origin="off">Use the <code><a href="api/forms/FormBuilder#array" class="code-anchor">FormBuilder.array()</a></code> method to define the array, and the <code><a href="api/forms/FormBuilder#control" class="code-anchor">FormBuilder.control()</a></code> method to populate the array with an initial control.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.ts" region="aliases" header="src/app/profile-editor/profile-editor.component.ts (aliases form array)" ng-version="9.0.0-rc.11"><div style="display:none">profileForm = this.fb.group({ firstName: ['', Validators.required], lastName: [''], address: this.fb.group({ street: [''], city: [''], <a href="api/animations/state" class="code-anchor">state</a>: [''], zip: [''] }), aliases: this.fb.array([ this.fb.control('') ]) });</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.ts (aliases form array)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.ts (aliases form array)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">profileForm </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">fb</span><span class="pun">.</span><span class="kwd">group</span><span class="pun">({</span><span class="pln">
  firstName</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">,</span><span class="pln"> </span><span class="typ">Validators</span><span class="pun">.</span><span class="pln">required</span><span class="pun">],</span><span class="pln">
  lastName</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">],</span><span class="pln">
  address</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">fb</span><span class="pun">.</span><span class="kwd">group</span><span class="pun">({</span><span class="pln">
    street</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">],</span><span class="pln">
    city</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">],</span><span class="pln">
    </span><a href="api/animations/state" class="code-anchor"><span class="pln">state</span></a><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">],</span><span class="pln">
    zip</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">''</span><span class="pun">]</span><span class="pln">
  </span><span class="pun">}),</span><span class="pln">
  aliases</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">fb</span><span class="pun">.</span><span class="pln">array</span><span class="pun">([</span><span class="pln">
    </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">fb</span><span class="pun">.</span><span class="pln">control</span><span class="pun">(</span><span class="str">''</span><span class="pun">)</span><span class="pln">
  </span><span class="pun">])</span><span class="pln">
</span><span class="pun">});</span></code>
    </pre></aio-code></code-example><p translation-result="on"><code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 中的这个 <code>aliases</code> 控件现在管理着一个控件，将来还可以动态添加多个。</p><p translation-origin="off">The aliases control in the form group instance is now populated with a single control until more controls are added dynamically.</p><h3 id="step-3-accessing-the-formarray-control" translation-result="on">步骤 3 - 访问 <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> 控件<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-3-accessing-the-formarray-control"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="step-3-accessing-the-formarray-control">Step 3: Accessing the FormArray control<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-3-accessing-the-formarray-control"><i class="material-icons">link</i></a></h3><p translation-result="on">相对于重复使用 <code>profileForm.get()</code> 方法获取每个实例的方式，getter 可以让你轻松访问表单数组各个实例中的别名。 表单数组实例用一个数组来代表未定数量的控件。通过 getter 来访问控件很方便，这种方法还能很容易地重复处理更多控件。</p><p translation-origin="off">A getter provides easy access to the aliases in the form array instance compared to repeating the <code>profileForm.get()</code> method to get each instance. The form array instance represents an undefined number of controls in an array. It's convenient to access a control through a getter, and this approach is easy to repeat for additional controls.</p><p translation-result="on">使用 getter 语法创建类属性 <code>aliases</code>，以从父表单组中接收表示绰号的表单数组控件。</p><p translation-origin="off">Use the getter syntax to create an <code>aliases</code> class property to retrieve the alias's form array control from the parent form group.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.ts" region="aliases-getter" header="src/app/profile-editor/profile-editor.component.ts (aliases getter)" ng-version="9.0.0-rc.11"><div style="display:none">get aliases() { return this.profileForm.get('aliases') as <a href="api/forms/FormArray" class="code-anchor">FormArray</a>; }</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.ts (aliases getter)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.ts (aliases getter)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">get</span><span class="pln"> aliases</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  </span><span class="kwd">return</span><span class="pln"> </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">profileForm</span><span class="pun">.</span><span class="kwd">get</span><span class="pun">(</span><span class="str">'aliases'</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">as</span><span class="pln"> </span><a href="api/forms/FormArray" class="code-anchor"><span class="typ">FormArray</span></a><span class="pun">;</span><span class="pln">
</span><span class="pun">}</span></code>
    </pre></aio-code></code-example><div class="alert is-helpful"><p translation-result="on"><em>注意</em>：因为返回的控件的类型是 <code><a href="api/forms/AbstractControl" class="code-anchor">AbstractControl</a></code>，所以你要为该方法提供一个显式的类型声明来访问 <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> 特有的语法。</p><p translation-origin="off"><strong>Note:</strong> Because the returned control is of the type <code><a href="api/forms/AbstractControl" class="code-anchor">AbstractControl</a></code>, you need to provide an explicit type to access the method syntax for the form array instance.</p></div><p translation-result="on">定义一个方法来把一个绰号控件动态插入到绰号 <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> 中。用 <code><a href="api/forms/FormArray#push" class="code-anchor">FormArray.push()</a></code> 方法把该控件添加为数组中的新条目。</p><p translation-origin="off">Define a method to dynamically insert an alias control into the alias's form array. The <code><a href="api/forms/FormArray#push" class="code-anchor">FormArray.push()</a></code> method inserts the control as a new item in the array.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.ts" region="add-alias" header="src/app/profile-editor/profile-editor.component.ts (add alias)" ng-version="9.0.0-rc.11"><div style="display:none">addAlias() { this.aliases.push(this.fb.control('')); }</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.ts (add alias)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.ts (add alias)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">addAlias</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">aliases</span><span class="pun">.</span><span class="pln">push</span><span class="pun">(</span><span class="kwd">this</span><span class="pun">.</span><span class="pln">fb</span><span class="pun">.</span><span class="pln">control</span><span class="pun">(</span><span class="str">''</span><span class="pun">));</span><span class="pln">
</span><span class="pun">}</span></code>
    </pre></aio-code></code-example><p translation-result="on">在这个模板中，这些控件会被迭代，把每个控件都显示为一个独立的输入框。</p><p translation-origin="off">In the template, each control is displayed as a separate input field.</p><h3 id="step-4-displaying-the-form-array-in-the-template" translation-result="on">步骤 4 - 在模板中显示表单数组<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-4-displaying-the-form-array-in-the-template"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="step-4-displaying-the-form-array-in-the-template">Step 4: Displaying the form array in the template<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#step-4-displaying-the-form-array-in-the-template"><i class="material-icons">link</i></a></h3><p translation-result="on">要想为表单模型添加 <code>aliases</code> ，你必须把它加入到模板中供用户输入。和 <code>FormGroupNameDirective</code> 提供的 <code><a href="api/forms/FormGroupName" class="code-anchor">formGroupName</a></code> 一样，<code>FormArrayNameDirective</code> 也使用 <code><a href="api/forms/FormArrayName" class="code-anchor">formArrayName</a></code> 在这个 <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> 实例和模板之间建立绑定。</p><p translation-origin="off">To attach the aliases from your form model, you must add it to the template. Similar to the <code><a href="api/forms/FormGroupName" class="code-anchor">formGroupName</a></code> input provided by <code>FormGroupNameDirective</code>, <code><a href="api/forms/FormArrayName" class="code-anchor">formArrayName</a></code> binds communication from the form array instance to the template with <code>FormArrayNameDirective</code>.</p><p translation-result="on">在 <code><a href="api/forms/FormGroupName" class="code-anchor">formGroupName</a></code> <code>&lt;div&gt;</code> 元素的结束标签下方，添加一段模板 HTML。</p><p translation-origin="off">Add the template HTML below after the <code>&lt;div&gt;</code> closing the <code><a href="api/forms/FormGroupName" class="code-anchor">formGroupName</a></code> element.</p><code-example path="reactive-forms/src/app/profile-editor/profile-editor.component.html" region="formarrayname" header="src/app/profile-editor/profile-editor.component.html (aliases form array template)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;div <a href="api/forms/FormArrayName" class="code-anchor">formArrayName</a>="aliases"&gt; &lt;h3&gt;Aliases&lt;/h3&gt; &lt;button (click)="addAlias()"&gt;Add Alias&lt;/button&gt; &lt;div *<a href="api/common/NgForOf" class="code-anchor">ngFor</a>="let alias of aliases.controls; let i=index"&gt; &lt;!-- The repeated alias template --&gt; &lt;label&gt; Alias: &lt;input type="text" [<a href="api/forms/FormControlName" class="code-anchor">formControlName</a>]="i"&gt; &lt;/label&gt; &lt;/div&gt; &lt;/div&gt;</div><header class="ng-star-inserted">src/app/profile-editor/profile-editor.component.html (aliases form array template)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/profile-editor/profile-editor.component.html (aliases form array template)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;div</span><span class="pln"> </span><a href="api/forms/FormArrayName" class="code-anchor"><span class="atn">formArrayName</span></a><span class="pun">=</span><span class="atv">"aliases"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;h3&gt;</span><span class="pln">Aliases</span><span class="tag">&lt;/h3&gt;</span><span class="pln"> </span><span class="tag">&lt;button</span><span class="pln"> (</span><span class="atn">click</span><span class="pln">)</span><span class="pun">=</span><span class="atv">"addAlias()"</span><span class="tag">&gt;</span><span class="pln">Add Alias</span><span class="tag">&lt;/button&gt;</span><span class="pln">

  </span><span class="tag">&lt;div</span><span class="pln"> *</span><a href="api/common/NgForOf" class="code-anchor"><span class="atn">ngFor</span></a><span class="pun">=</span><span class="atv">"let alias of aliases.controls; let i=index"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="com">&lt;!-- The repeated alias template --&gt;</span><span class="pln">
    </span><span class="tag">&lt;label&gt;</span><span class="pln">
      Alias:
      </span><span class="tag">&lt;input</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text"</span><span class="pln"> [</span><a href="api/forms/FormControlName" class="code-anchor"><span class="atn">formControlName</span></a><span class="pln">]</span><span class="pun">=</span><span class="atv">"i"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;/label&gt;</span><span class="pln">
  </span><span class="tag">&lt;/div&gt;</span><span class="pln">
</span><span class="tag">&lt;/div&gt;</span></code>
    </pre></aio-code></code-example><p translation-result="on"><code>*<a href="api/common/NgForOf" class="code-anchor">ngFor</a></code> 指令对 <code>aliases</code> <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> 提供的每个 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 进行迭代。因为 <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> 中的元素是匿名的，所以你要把<em>索引号</em>赋值给 <code>i</code> 变量，并且把它传给每个控件的 <code><a href="api/forms/FormControlName" class="code-anchor">formControlName</a></code> 输入属性。</p><p translation-origin="off">The <code>*<a href="api/common/NgForOf" class="code-anchor">ngFor</a></code> directive iterates over each form control instance provided by the aliases form array instance. Because form array elements are unnamed, you assign the index to the <code>i</code> variable and pass it to each control to bind it to the <code><a href="api/forms/FormControlName" class="code-anchor">formControlName</a></code> input.</p><div class="lightbox"><img src="generated/images/guide/reactive-forms/profile-editor-4.png" alt="Profile Editor Aliases" width="414" height="722"></div><p translation-result="on">每当新的 <code>alias</code> 加进来时，<code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> 的实例就会基于这个索引号提供它的控件。这将允许你在每次计算根控件的状态和值时跟踪每个控件。</p><p translation-origin="off">Each time a new alias instance is added, the new form array instance is provided its control based on the index. This allows you to track each individual control when calculating the status and value of the root control.</p><h4 id="adding-an-alias" translation-result="on">添加绰号<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#adding-an-alias"><i class="material-icons">link</i></a></h4><h4 translation-origin="off" id="adding-an-alias">Adding an alias<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#adding-an-alias"><i class="material-icons">link</i></a></h4><p translation-result="on">最初，表单只包含一个绰号字段，点击 <code>Add Alias</code> 按钮，就出现了另一个字段。你还可以验证由模板底部的“Form Value”显示出来的表单模型所报告的这个绰号数组。</p><p translation-origin="off">Initially, the form contains one <code>Alias</code> field. To add another field, click the <strong>Add Alias</strong> button. You can also validate the array of aliases reported by the form model displayed by <code><a href="api/forms/Form" class="code-anchor">Form</a> Value</code> at the bottom of the template.</p><div class="alert is-helpful"><p translation-result="on"><em>注意</em>：除了为每个绰号使用 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 之外，你还可以改用 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 来组合上一些额外字段。对其中的每个条目定义控件的过程和前面没有区别。</p><p translation-origin="off"><strong>Note:</strong> Instead of a form control instance for each alias, you can compose another form group instance with additional fields. The process of defining a control for each item is the same.</p></div><a id="appendix"></a><h2 id="appendix" translation-result="on">附录<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#appendix"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="appendix">Appendix<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#appendix"><i class="material-icons">link</i></a></h2><a id="reactive-forms-api"></a><h3 id="reactive-forms-api" translation-result="on">响应式表单 API<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#reactive-forms-api"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="reactive-forms-api">Reactive forms API<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#reactive-forms-api"><i class="material-icons">link</i></a></h3><p translation-result="on">下面列出了用于创建和管理表单控件的基础类和服务。</p><p translation-origin="off">Listed below are the base classes and services used to create and manage form controls.</p><h4 id="classes" translation-result="on">类<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#classes"><i class="material-icons">link</i></a></h4><h4 translation-origin="off" id="classes">Classes<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#classes"><i class="material-icons">link</i></a></h4><table><tbody><tr><th><p translation-result="on">类</p><p translation-origin="off">Class</p></th><th><p translation-result="on">说明</p><p translation-origin="off">Description</p></th></tr><tr><td style="vertical-align:top"><p> <code><a href="api/forms/AbstractControl" class="code-anchor">AbstractControl</a></code></p></td><td><p translation-result="on">所有三种表单控件类（<code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code>、<code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 和 <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code>）的抽象基类。它提供了一些公共的行为和属性。</p><p translation-origin="off">The abstract base class for the concrete form control classes <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code>, <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code>, and <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code>. It provides their common behaviors and properties.</p></td></tr><tr><td style="vertical-align:top"><p> <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code></p></td><td><p translation-result="on">管理单体表单控件的值和有效性状态。它对应于 HTML 的表单控件，比如 <code>&lt;input&gt;</code> 或 <code>&lt;select&gt;</code>。</p><p translation-origin="off">Manages the value and validity status of an individual form control. It corresponds to an HTML form control such as <code>&lt;input&gt;</code> or <code>&lt;select&gt;</code>.</p></td></tr><tr><td style="vertical-align:top"><p> <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code></p></td><td><p translation-result="on">管理一组 <code><a href="api/forms/AbstractControl" class="code-anchor">AbstractControl</a></code> 实例的值和有效性状态。该组的属性中包括了它的子控件。组件中的顶级表单就是 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code>。</p><p translation-origin="off">Manages the value and validity state of a group of <code><a href="api/forms/AbstractControl" class="code-anchor">AbstractControl</a></code> instances. The group's properties include its child controls. The top-level form in your component is <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code>.</p></td></tr><tr><td style="vertical-align:top"><p> <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code></p></td><td><p translation-result="on">管理一些 <code><a href="api/forms/AbstractControl" class="code-anchor">AbstractControl</a></code> 实例数组的值和有效性状态。</p><p translation-origin="off">Manages the value and validity state of a numerically indexed array of <code><a href="api/forms/AbstractControl" class="code-anchor">AbstractControl</a></code> instances.</p></td></tr><tr><td style="vertical-align:top"><p> <code><a href="api/forms/FormBuilder" class="code-anchor">FormBuilder</a></code></p></td><td><p translation-result="on">一个可注入的服务，提供一些用于提供创建控件实例的工厂方法。</p><p translation-origin="off">An injectable service that provides factory methods for creating control instances.</p></td></tr></tbody></table><h4 id="directives" translation-result="on">指令<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#directives"><i class="material-icons">link</i></a></h4><h4 translation-origin="off" id="directives">Directives<a title="Link to this heading" class="header-link" aria-hidden="true" href="guide/reactive-forms#directives"><i class="material-icons">link</i></a></h4><table><tbody><tr><th><p translation-result="on">指令</p><p translation-origin="off">Directive</p></th><th><p translation-result="on">说明</p><p translation-origin="off">Description</p></th></tr><tr><td style="vertical-align:top"><p> <code><a href="api/forms/FormControlDirective" class="code-anchor">FormControlDirective</a></code></p></td><td><p translation-result="on">把一个独立的 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 实例绑定到表单控件元素。</p><p translation-origin="off">Syncs a standalone <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> instance to a form control element.</p></td></tr><tr><td style="vertical-align:top"><p> <code><a href="api/forms/FormControlName" class="code-anchor">FormControlName</a></code></p></td><td><p translation-result="on">把一个现有 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 中的 <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> 实例根据名字绑定到表单控件元素。</p><p translation-origin="off">Syncs <code><a href="api/forms/FormControl" class="code-anchor">FormControl</a></code> in an existing <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> instance to a form control element by name.</p></td></tr><tr><td style="vertical-align:top"><p> <code><a href="api/forms/FormGroupDirective" class="code-anchor">FormGroupDirective</a></code></p></td><td><p translation-result="on">把一个现有的 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 实例绑定到 DOM 元素。</p><p translation-origin="off">Syncs an existing <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> instance to a DOM element.</p></td></tr><tr><td style="vertical-align:top"><p> <code><a href="api/forms/FormGroupName" class="code-anchor">FormGroupName</a></code></p></td><td><p translation-result="on">把一个内嵌的 <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> 实例绑定到一个 DOM 元素。</p><p translation-origin="off">Syncs a nested <code><a href="api/forms/FormGroup" class="code-anchor">FormGroup</a></code> instance to a DOM element.</p></td></tr><tr><td style="vertical-align:top"><p> <code><a href="api/forms/FormArrayName" class="code-anchor">FormArrayName</a></code></p></td><td><p translation-result="on">把一个内嵌的 <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> 实例绑定到一个 DOM 元素。</p><p translation-origin="off">Syncs a nested <code><a href="api/forms/FormArray" class="code-anchor">FormArray</a></code> instance to a DOM element.</p></td></tr></tbody></table></div></div></aio-doc-viewer></main></mat-sidenav-content></mat-sidenav-container><div class="toc-container no-print ng-star-inserted"><aio-lazy-ce selector="aio-toc"><aio-toc ng-version="9.0.0-rc.11"><div class="toc-inner no-print collapsed ng-star-inserted"><ul class="toc-list"><li class="h1 ng-star-inserted active" title="响应式表单"><a href="guide/reactive-forms#reactive-forms">响应式表单</a></li><li class="h2 ng-star-inserted" title="响应式表单简介"><a href="guide/reactive-forms#introduction-to-reactive-forms">响应式表单简介</a></li><li class="h2 ng-star-inserted" title="快速上手"><a href="guide/reactive-forms#getting-started">快速上手</a></li><li class="h3 ng-star-inserted" title="步骤 1 - 注册 ReactiveFormsModule"><a href="guide/reactive-forms#step-1-registering-the-reactive-forms-module">步骤 1 - 注册 <code>ReactiveFormsModule</code></a></li><li class="h3 ng-star-inserted" title="步骤 2 - 生成并导入一个新的表单控件"><a href="guide/reactive-forms#step-2-generating-and-importing-a-new-form-control">步骤 2 - 生成并导入一个新的表单控件</a></li><li class="h3 ng-star-inserted" title="步骤 3 - 在模板中注册该控件"><a href="guide/reactive-forms#step-3-registering-the-control-in-the-template">步骤 3 - 在模板中注册该控件</a></li><li class="h2 ng-star-inserted" title="管理控件的值"><a href="guide/reactive-forms#managing-control-values">管理控件的值</a></li><li class="h3 ng-star-inserted" title="显示表单控件的值"><a href="guide/reactive-forms#displaying-a-form-control-value">显示表单控件的值</a></li><li class="h3 ng-star-inserted" title="替换表单控件的值"><a href="guide/reactive-forms#replacing-a-form-control-value">替换表单控件的值</a></li><li class="h2 ng-star-inserted" title="把表单控件分组"><a href="guide/reactive-forms#grouping-form-controls">把表单控件分组</a></li><li class="h3 ng-star-inserted" title="步骤 1 - 创建 FormGroup 实例"><a href="guide/reactive-forms#step-1-creating-a-formgroup-instance">步骤 1 - 创建 <code>FormGroup</code> 实例</a></li><li class="h3 ng-star-inserted" title="步骤 2 - 关联 FormGroup 的模型和视图"><a href="guide/reactive-forms#step-2-associating-the-formgroup-model-and-view">步骤 2 - 关联 <code>FormGroup</code> 的模型和视图</a></li><li class="h3 ng-star-inserted" title="保存表单数据"><a href="guide/reactive-forms#saving-form-data">保存表单数据</a></li><li class="h2 ng-star-inserted" title="嵌套的表单组"><a href="guide/reactive-forms#creating-nested-form-groups">嵌套的表单组</a></li><li class="h3 ng-star-inserted" title="步骤 1 - 创建嵌套的分组"><a href="guide/reactive-forms#step-1-creating-a-nested-group">步骤 1 - 创建嵌套的分组</a></li><li class="h3 ng-star-inserted" title="步骤 2 - 在模板中分组内嵌的表单"><a href="guide/reactive-forms#step-2-grouping-the-nested-form-in-the-template">步骤 2 - 在模板中分组内嵌的表单</a></li><li class="h2 ng-star-inserted" title="部分模型更新"><a href="guide/reactive-forms#partial-model-updates">部分模型更新</a></li><li class="h3 ng-star-inserted" title="修补（Patching）模型值"><a href="guide/reactive-forms#patching-the-model-value">修补（Patching）模型值</a></li><li class="h2 ng-star-inserted" title="使用 FormBuilder 来生成表单控件"><a href="guide/reactive-forms#generating-form-controls-with-formbuilder">使用 <code>FormBuilder</code> 来生成表单控件</a></li><li class="h3 ng-star-inserted" title="步骤 1 - 导入 FormBuilder 类"><a href="guide/reactive-forms#step-1-importing-the-formbuilder-class">步骤 1 - 导入 <code>FormBuilder</code> 类</a></li><li class="h3 ng-star-inserted" title="步骤 2 - 注入 FormBuilder 服务"><a href="guide/reactive-forms#step-2-injecting-the-formbuilder-service">步骤 2 - 注入 <code>FormBuilder</code> 服务</a></li><li class="h3 ng-star-inserted" title="步骤 3 - 生成表单控件"><a href="guide/reactive-forms#step-3-generating-form-controls">步骤 3 - 生成表单控件</a></li><li class="h2 ng-star-inserted" title="简单表单验证"><a href="guide/reactive-forms#simple-form-validation">简单表单验证</a></li><li class="h3 ng-star-inserted" title="步骤 1 - 导入验证器函数"><a href="guide/reactive-forms#step-1-importing-a-validator-function">步骤 1 - 导入验证器函数</a></li><li class="h3 ng-star-inserted" title="步骤 2 - 把字段设为必填（required）"><a href="guide/reactive-forms#step-2-making-a-field-required">步骤 2 - 把字段设为必填（required）</a></li><li class="h3 ng-star-inserted" title="显示表单状态"><a href="guide/reactive-forms#displaying-form-status">显示表单状态</a></li><li class="h2 ng-star-inserted" title="使用表单数组管理动态控件"><a href="guide/reactive-forms#dynamic-controls-using-form-arrays">使用表单数组管理动态控件</a></li><li class="h3 ng-star-inserted" title="步骤 1 - 导入 FormArray"><a href="guide/reactive-forms#step-1-importing-the-formarray-class">步骤 1 - 导入 <code>FormArray</code></a></li><li class="h3 ng-star-inserted" title="步骤 2 - 定义 FormArray"><a href="guide/reactive-forms#step-2-defining-a-formarray-control">步骤 2 - 定义 <code>FormArray</code></a></li><li class="h3 ng-star-inserted" title="步骤 3 - 访问 FormArray 控件"><a href="guide/reactive-forms#step-3-accessing-the-formarray-control">步骤 3 - 访问 <code>FormArray</code> 控件</a></li><li class="h3 ng-star-inserted" title="步骤 4 - 在模板中显示表单数组"><a href="guide/reactive-forms#step-4-displaying-the-form-array-in-the-template">步骤 4 - 在模板中显示表单数组</a></li><li class="h2 ng-star-inserted" title="附录"><a href="guide/reactive-forms#appendix">附录</a></li><li class="h3 ng-star-inserted" title="响应式表单 API"><a href="guide/reactive-forms#reactive-forms-api">响应式表单 API</a></li></ul></div></aio-toc></aio-lazy-ce></div><footer class="no-print"><aio-footer><div class="grid-fluid"><div class="footer-block ng-star-inserted"><h3>资源</h3><ul><li class="ng-star-inserted"><a class="link" href="about" title="Angular 贡献者。">关于</a></li><li class="ng-star-inserted"><a class="link" href="resources" title="网络上的 Angular 工具、培训、博客等">资源列表</a></li><li class="ng-star-inserted"><a class="link" href="presskit" title="我们的联系方式、LOGO 和品牌">宣传资料</a></li><li class="ng-star-inserted"><a class="link" href="https://blog.angular.io/" title="Angular 官方博客">博客</a></li><li class="ng-star-inserted"><a class="link" href="analytics" title="Angular 使用情况分析">使用情况分析</a></li></ul></div><div class="footer-block ng-star-inserted"><h3>帮助</h3><ul><li class="ng-star-inserted"><a class="link" href="https://stackoverflow.com/questions/tagged/angular" title="Stack Overflow: 这里的社区会回答你关于 Angular 的技术问题">Stack Overflow</a></li><li class="ng-star-inserted"><a class="link" href="https://gitter.im/angular/angular" title="和老鸟聊 Angular">Gitter</a></li><li class="ng-star-inserted"><a class="link" href="https://github.com/angular/angular/issues" title="在 github 上报告问题和建议。">报告问题</a></li><li class="ng-star-inserted"><a class="link" href="https://github.com/angular/code-of-conduct/blob/master/CODE_OF_CONDUCT.md" title="让我们彼此尊重">行为规范</a></li></ul></div><div class="footer-block ng-star-inserted"><h3>社区</h3><ul><li class="ng-star-inserted"><a class="link" href="events" title="Angular events around the world.">活动</a></li><li class="ng-star-inserted"><a class="link" href="http://www.meetup.com/topics/angularjs/" title="参加聚会，向别的开发人员学习">聚会</a></li><li class="ng-star-inserted"><a class="link" href="https://twitter.com/angular" title="Twitter">Twitter</a></li><li class="ng-star-inserted"><a class="link" href="https://github.com/angular/angular" title="GitHub">GitHub</a></li><li class="ng-star-inserted"><a class="link" href="contribute" title="向 Angular 做贡献">做贡献</a></li></ul></div><div class="footer-block ng-star-inserted"><h3>多语言</h3><ul><li class="ng-star-inserted"><a class="link" href="https://angular.io/" title="English Version.">English Version</a></li><li class="ng-star-inserted"><a class="link" href="https://angular.tw/" title="正體中文版">正體中文版</a></li><li class="ng-star-inserted"><a class="link" href="https://angular.jp/" title="日本語版">日本語版</a></li><li class="ng-star-inserted"><a class="link" href="https://angular.kr/" title="한국어">한국어</a></li></ul></div></div><p>Super-powered by Google ©2010-2020. 代码授权方式：<a href="license" title="License text">MIT-style License</a>. 文档授权方式：<a href="http://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a>.</p><p>当前版本：9.0.1-build.79+sha.55f1ef01.</p></aio-footer></footer><div class="cdk-visually-hidden ng-star-inserted"><mat-icon role="img" class="mat-icon notranslate material-icons mat-icon-no-color" aria-hidden="true">&nbsp;</mat-icon></div></aio-shell><noscript><div class="background-sky hero"></div><section id="intro" style="text-shadow:1px 1px #1976d2"><div class="hero-logo"><img src="assets/images/logos/angular/angular.svg" width="250" height="250" alt="Angular"></div><div class="homepage-container"><div class="hero-headline">一套框架，多种平台<br>移动 &amp; 桌面</div></div></section><h2 style="color:red;margin-top:40px;position:relative;text-align:center;text-shadow:1px 1px #fafafa"><b><i>该网站需要浏览器支持 JavaScript</i></b></h2></noscript><script src="runtime-es2015.ee607cf78010348c8334.js" type="module"></script><script src="runtime-es5.ee607cf78010348c8334.js" nomodule="" defer=""></script><script src="polyfills-es5.1494ca908613f3429457.js" nomodule="" defer=""></script><script src="polyfills-es2015.9057a05c650bf60ecbf4.js" type="module"></script><script src="main-es2015.9cd62e243bd182514a19.js" type="module"></script><script src="main-es5.9cd62e243bd182514a19.js" nomodule="" defer=""></script><div class="cdk-live-announcer-element cdk-visually-hidden" aria-atomic="true" aria-live="polite"></div></body></html>